Behaviour for persisting job state across VM restarts.
Forks can implement this behaviour to swap the storage backend
(e.g. PostgreSQL, Redis, S3, etc.). The default Core.JobStore.Memory
provides zero-durability in-memory IDs for prototyping.
Configuration
config :my_app, :job_store, Core.JobStore.SQLite
config :my_app, :job_store_opts, database: "priv/jobs.db"All callbacks are invoked synchronously by Core.Workers.JobQueue.
Summary
Callbacks
Remove old completed / failed jobs. opts contains :max_age_days.
Fetch a single job by id.
Initialise the store (create tables, indexes, etc.).
Persist a new job. Must return the job with an assigned :id.
List jobs, optionally filtered by status.
Partially update a job by id. changes is a keyword list of fields.
Types
@type opts() :: Keyword.t()
Callbacks
@callback cleanup(Keyword.t()) :: :ok
Remove old completed / failed jobs. opts contains :max_age_days.
@callback get_job(pos_integer()) :: {:ok, Core.Workers.Job.t()} | {:error, :not_found}
Fetch a single job by id.
Initialise the store (create tables, indexes, etc.).
@callback insert_job(Core.Workers.Job.t()) :: {:ok, Core.Workers.Job.t()} | {:error, term()}
Persist a new job. Must return the job with an assigned :id.
@callback list_jobs(Keyword.t()) :: [Core.Workers.Job.t()]
List jobs, optionally filtered by status.
@callback update_job(pos_integer(), changes :: Keyword.t()) :: :ok | {:error, term()}
Partially update a job by id. changes is a keyword list of fields.