What is a recommended job length?

The docs have a few lines like

A task may run for too long and would be interrupted by code releases or other node restarts
(from: Recursive Jobs — Oban v2.19.4)

extra long running jobs
(from: Ready for Production — Oban v2.19.4)

Is there any general guidance on what sort of threshold to aim to keep jobs under? i.e. should most jobs aim to complete in something like 15 seconds?

Jobs don’t hold a database connection and they aren’t executed in a transaction, so it’s safe to run them for as long as needed. There’s no limit imposed by Oban on how long a job can run, and it’s entirely up to a few factors in your application:

  1. How frequently does the app restart?
  2. How will the jobs handle interruption?

If your application restarts frequently during the day due to deployments, and you’re running jobs that take hours, you’ll need to ensure they can restart safely. Some tasks can be broken up and parallelized, while others like video transcoding or archiving may take an hour or more and can’t be broken into smaller segments.

Shutting Down

The shutdown_grace_period config option determines how long Oban will wait for jobs to complete when the application goes to shut down. The default period is 15 seconds, but you can increase it to a larger duration so jobs have longer to shut down. Some applications extend shutdown to an hour to allow long running jobs to complete without restarting and throwing away the previous effort.

8 Likes

Thank you! Those are some helpful questions and guidelines. Also wow an hour is a long time to give to allow a job to shutdown.