View Source Bildad.Job.JobEngine (Bildad v0.1.5)
This module contains the logic for enqueuing, running, killing and expiring jobs in the Bildad job scheduling framework.
Summary
Functions
Used to mark a job as completed successfully.
Enqueues a job and runs it immediately.
Adds a job to the queue. The order it will be run in will be based on priority and resource availability.
Enqueues a job and triggers the job engine to run immediately.
Used when a job is not running on any node and the expiration time has been reached.
Jobs that come to completion and are not successful are marked as failed.
Locates the Elixir process by the job identifier. If the process is not running or is running on another node then nil is returned.
Utility function go get the number of successful jobs and the number of jobs that failed.
The queue entry points to the current run which has its retry count. This function increments that number by one OR it returns 0 if there is not a currently running job (which is the initial state of an enqueued job).
If the Elixir process is running on this node then it kills the process and updates the database record.
Launches the Elixir process for the job passing it the job context. It registers the process with the job identifier so that it can be found later.
Removes a job from the queue. This is typically called when a job is completed or when a user wishes to no longer run the job.
This function is called by the job scheduler to run a job.
This function is called by the job scheduler to run the job engine.
This function is called by the job scheduler to stop a job that is currently running.
This ONLY updates the record in the database, it does NOT stop the elixir process.
To stop the Elixir process if it is still running then kill_a_job
should be called.
Tries to kill the process by sending an exit signal.
Each job has a schema that defines the shape of the data that will be passed to the job module when it is run.
Functions
Used to mark a job as completed successfully.
enqueue_and_run_job(job_config, job_template, job_context, opts \\ %{})
View SourceEnqueues a job and runs it immediately.
This should be used sparingly as it bypasses the priority of other jobs in the queue.
Adds a job to the queue. The order it will be run in will be based on priority and resource availability.
Each message contains a job_context
which is a map of data that will be passed to the job module when it is run.
This job context must conform to the schema defined in the job template.
enqueue_job_and_trigger_engine(job_config, job_template, job_context, opts \\ %{})
View SourceEnqueues a job and triggers the job engine to run immediately.
If there are other jobs ahead of this one in the queue that are higher priority, they will be run first.
This is the preferred over enqueue_and_run_job
as it respects the priority of other jobs in the queue.
TODO: This should make the same API call that the cron job makes and it should check to see if the job engine is already running before starting it.
Used when a job is not running on any node and the expiration time has been reached.
Jobs that come to completion and are not successful are marked as failed.
Locates the Elixir process by the job identifier. If the process is not running or is running on another node then nil is returned.
Utility function go get the number of successful jobs and the number of jobs that failed.
The queue entry points to the current run which has its retry count. This function increments that number by one OR it returns 0 if there is not a currently running job (which is the initial state of an enqueued job).
If the Elixir process is running on this node then it kills the process and updates the database record.
If not, nothing happens on this node. The other nodes should being runnig this function as well and the
process will be stopped on one of them.
If the process is not running on any node the job will eventually expire when the expiration time is reached.
The expire_a_job
function should be called to handle that case. (This is done by the job engine.)
Launches the Elixir process for the job passing it the job context. It registers the process with the job identifier so that it can be found later.
Removes a job from the queue. This is typically called when a job is completed or when a user wishes to no longer run the job.
This function is called by the job scheduler to run a job.
This function is called by the job scheduler to run the job engine.
This should be called by a single cron job in your environment so that the engine is run on one node at a time.
This function is called by the job scheduler to stop a job that is currently running.
This ONLY updates the record in the database, it does NOT stop the elixir process.
To stop the Elixir process if it is still running then kill_a_job
should be called.
Tries to kill the process by sending an exit signal.
Each job has a schema that defines the shape of the data that will be passed to the job module when it is run.