-
Notifications
You must be signed in to change notification settings - Fork 19
Backend Pattern Job
Matt Roth edited this page Oct 7, 2022
·
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:
Prior to Deployment
- 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
After Deployment
Choose one of the following options or both of the options below to enable the job in production:
-
For jobs triggered on an interval (Option 1):
- 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
- The new lambda will be deployed upon merging the new job to master in
serverless.yml
- Add job to
-
For jobs triggered on-demand (Option 2):
- The class that is triggering your job should inherit from
RunAsyncable
- Use the
perform_later_or_now
helper method. 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.