Job Scheduling


Configuring a cron job or windows task is common for web apps. Spark utilizes Coravel’s scheduler to accomplish this.


Spark registers the scheduler in the Application.Startup.AppServiceRegistration.AddAppServices() method for you.


Your individual jobs also need to be registered in the service container. This can be done in the Application.Startup.AppServiceRegistration.AddJobServices() method.

private static IServiceCollection AddJobServices(this IServiceCollection services)
    return services;

Defining Schedules

Jobs are scheduled in the Application.Startup.Scheduler.RegisterScheduledJobs() method.

Inside of that method, the UseScheduler() method is called. Your scheduled jobs and their intervals are defined inside of it.

public static class Scheduler
    public static IServiceProvider RegisterScheduledJobs(this IServiceProvider services)
        services.UseScheduler(scheduler =>
            // example scheduled job
        return services;

Scheduling Jobs With Parameters

If you have a job that expects parameters, you can use the ScheduleWithParams<T>() method.

For example, if you had a job that accepted a string parameter:

public class ExampleJob : IInvocable
    private string _someParm;

    public WeatherJob(string param)
        this._someParm = param;

    public Task Invoke()
        // lookup states weather data
        return Task.CompletedTask;

You could pass the parameter like this:

    .ScheduleWithParams<ExampleJob>("some string param")


When scheduling jobs, you will also need to specify the interval in which they run. There are many schedule intervals that you may assign to a job:

// Run the job using a Cron expression
.Cron("* * * * *")

// Run the job every second

// Run the job every five seconds            

// Run the job every ten seconds

// Run the job every fifteen seconds

// Run the job every thirty seconds

// 	Run the job every 3 seconds

// Run the job once a minute

// Run the job every five minutes

// Run the job every ten minutes

// Run the job every fifteen minutes

// Run the job every thirty minutes

// Run the job every hour

// Run the job at 12 minutes past every hour

// 	Run the job once a day at midnight

// Run the job once a day at 1 p.m. UTC

// Run the job once a day at 1:30 p.m. UTC
.DailyAt(13, 30)

// Run the job once a week

// Run the job on the first of every month midnight

The scheduler uses UTC time by default

Day Contraints

Once you specify an interval, you can also restrict what day’s the job is allowed to run on.


You can also chain these methods.

For instance, the following would mean a job runs every hour on Monday and Wednesdays:



By default, the scheduler uses UTC time to trigger jobs.

If you would like to run your schedules against a particular time zone, use the Zoned() method.


Preventing Job Overlap

By default, scheduled jobs will run even if the previous instance of the job is still running.

To prevent this, you may use the PreventOverlapping() method.


This method takes in one paramater, a unique string key. The key is whats used to determine if the job has an instance running or not when the scheduler goes to trigger a job.

Stay up to date with Spark on Twitter or our Newsletter

Looking for .NET jobs? Check out Dotnet Jobs for weekly job postings.