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/jobsthat implementProcess
- Read and make sure you understand all structs in
- Create a new
JobTypeinsrc/models/job.go.- Add the
JobTypeto the const list- Make sure the string is 100% unique within that list!
- Add the new
JobTypeto theValidJobTypeslist
- Add the
- Create a new struct that implements the
Processmethod.- 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
JobTypeto the concreteProcessimplementor- This is done in
src/jobs/jobs.go, in theDBJobToProcessorfunction
- 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 thewatchallargument) will run your new job type.
- For almost any new job, you’ll just add the type to an existing runner
function in