-
Notifications
You must be signed in to change notification settings - Fork 19
Backend Pattern Job
Ferris Tseng edited this page Feb 8, 2021
·
17 revisions
Jobs are responsible for doing asynchronous work in Caseflow.
app/jobs
Also, jobs that are triggered on an interval should be declared in:
Checklist:
- Inherit from
ApplicationJob
- Ensure
application_attr
andqueue_with_priority
are set. These are needed for the async job trigger to start your job, and are also used to tag Datadog metrics - Define a
perform
method - Ensure you set the
RequestStore[:current_user]
if parts of your job depend on that being set - Ensure that you are handling errors and retry if necessary
- For jobs triggered on an interval:
- Add job to
serverless.yml
for jobs triggered on an interval. Note: You have to add to the end of the list here otherwise the job won't be detected - Add job to
SUPPORTED_JOBS
injobs_controller.rb
- Add job to
- For jobs triggered on-demand:
- The class that is triggering your job should inherit from
RunAsyncable
- Use the
perform_later_or_now
. This method will launch async jobs inline in dev.
- The class that is triggering your job should inherit from
Jobs are good for things that take a long time to do or for when we need to interact with an unreliable external service (Asyncable models can help with this problem). There is some overhead to setting them up, so don't rely on them too much to do really simple tasks.