Add Job Types
When a new kind of job is required for backend processing, it has to be done properly in order to ensure it is used, set up, and processed by NCA.
- Make sure there aren’t already existing jobs that do what you want! There
are a lot of jobs in NCA already, and some are meant to be very generic, such
as
JobTypeRenameDir
.- Read and make sure you understand all structs in
src/jobs
that implementProcess
- Read and make sure you understand all structs in
- Create a new
JobType
insrc/models/job.go
.- Add the
JobType
to the const list- Make sure the string is 100% unique within that list!
- Add the new
JobType
to theValidJobTypes
list
- Add the
- Create a new struct that implements the
Process
method.- Use an existing Go file if it makes sense (e.g., another metadata or
filesystem job) or create a new one in
src/jobs/
. - Make sure you document the type! What is its purpose?
- Need an example? The metadata jobs are very simple and can be found in
src/jobs/metadata_jobs.go
.
- Use an existing Go file if it makes sense (e.g., another metadata or
filesystem job) or create a new one in
- Wire up the
JobType
to the concreteProcess
implementor- This is done in
src/jobs/jobs.go
, in theDBJobToProcessor
function
- This is done in
- Queue a job of the new type.
- See
src/jobs/queue.go
- You might need to create a new arg value in
src/jobs/queue.go
, likeJobArgSource
,JobArgWorkflowStep
, etc. - You will certainly need to create the job and push it into a queue. This
happens in a
Queue...
function (e.g.,QueueBatchForDeletion
).
- See
- Make something run jobs of the new type.
- For almost any new job, you’ll just add the type to an existing runner
function in
src/cmd/run-jobs/main.go
(runAllQueues
). This ensures a simple job runner invocation (with thewatchall
argument) will run your new job type.
- For almost any new job, you’ll just add the type to an existing runner
function in