Skip to content

Periodic Job

Lucas Nelaupe edited this page Jan 12, 2018 · 10 revisions

Create a task that will run periodically.

JobBuilder(jobType: CheckForTweet.type)
        // Wait 10 seconds before first execution
        .delay(time: 10)
        // Number if times you want to repeat the job (can be Int.max)
        // Wait 30 seconds between each run
        .periodic(limit: .limited(3), interval: 15)
        .schedule(queue: queue) // Add to queue

Execution timeline for CheckForTweet

     delay       1st       interval        2nd        interval        3rd
     10 sec      run        15 sec         run         15 sec         run
---|----------|00000000|---------------|0000000000|---------------|0000000000|X
   ^          ^        ^               ^          ^               ^          ^
Schedule     run      done             run        done           run       finish

Error handling

In case of error, the job will not be rescheduled by default. To do so, you will need to add retry(Limit)

Deadline

You can alternatively specify a time until when the job can run. Execution will be stoped after the deadline

jobBuilder.deadline(date: Date(...))

Clone this wiki locally