Kiq v0.1.0 Kiq.Job View Source
Used to construct a Sidekiq compatible job.
The job complies with the Sidekiq Job Format, and contains the following fields:
jid
- A 12 byte random number as a 24 character hex encoded stringpid
— Process id of the worker running the job, defaults to the calling processclass
- The worker class which is responsible for executing the jobargs
- The arguments passed which should be passed to the workerqueue
- The queue where a job should be enqueued, defaults to “default”retry
- Tells the Kiq worker to retry the enqueue jobretry_count
- The number of times we’ve retried so farat
— A time at or after which a scheduled job should be performed, in Unix formatcreated_at
- When the job was created, in Unix formatenqueue_at
- When the job was enqueued, in Unix formatfailed_at
- The first time the job failed, in Unix formatretried_at
— The last time the job was retried, in Unix formaterror_message
— The message from the last exceptionerror_class
— The exception module (or class, in Sidekiq terms)backtrace
- The number of lines of error backtrace to store, defaults to none
Link to this section Summary
Functions
Decode an encoded job from JSON into a Job struct
Encode a job as JSON
Build a new Job
struct with all dynamic arguments populated
Generate a compliant, entirely random, job id
Link to this section Types
Link to this type
t()
View Source
t() :: %Kiq.Job{ args: [any()], at: Kiq.Timestamp.t(), class: binary(), created_at: Kiq.Timestamp.t(), enqueued_at: Kiq.Timestamp.t(), error_class: binary(), error_message: binary(), failed_at: Kiq.Timestamp.t(), jid: binary(), pid: pid(), queue: binary(), retried_at: Kiq.Timestamp.t(), retry: boolean() | non_neg_integer(), retry_count: non_neg_integer() }
Link to this section Functions
Decode an encoded job from JSON into a Job struct.
All keys are atomized, including keys within arguments. This does not use
String.to_existing_atom/1
, so be wary of encoding large maps.
Example
iex> job = Kiq.Job.decode(~s({"class":"MyWorker","args":[1,2]}))
...> Map.take(job, [:class, :args])
%{class: "MyWorker", args: [1, 2]}
iex> job = Kiq.Job.decode(~s({"class":"MyWorker","args":{"a":1}}))
...> Map.get(job, :args)
%{a: 1}
Encode a job as JSON.
During the encoding process any keys with nil
values are removed.
Build a new Job
struct with all dynamic arguments populated.
iex> Kiq.Job.new(%{class: "Worker"}) |> Map.take([:class, :args, :queue])
%{class: "Worker", args: [], queue: "default"}
iex> Kiq.Job.new(module: "Worker") |> Map.get(:class)
"Worker"
Link to this function
random_jid(size \\ 12)
View Source
random_jid(size :: pos_integer()) :: binary()
Generate a compliant, entirely random, job id.
Example
iex> Kiq.Job.random_jid() =~ ~r/^[0-9a-z]{24}$/
true
iex> job_a = Kiq.Job.random_jid()
...> job_b = Kiq.Job.random_jid()
...> job_a == job_b
false