Module Sihl_queue
type instance_status= Sihl.Contract.Queue.instance_status=|Pending|Succeeded|Failed|Cancelledinstance_statusis the status of the job on the queue.
type instance= Sihl.Contract.Queue.instance={id : string;name : string;input : string;tries : int;next_run_at : Ptime.t;max_tries : int;status : instance_status;last_error : string option;last_error_at : Ptime.t option;}instanceis a queued job with a concrete input.
type 'a job= 'a Sihl.Contract.Queue.job={name : string;encode : 'a -> string;decode : string -> ('a, string) Result.t;handle : 'a -> (unit, string) Result.t Lwt.t;failed : string -> instance -> unit Lwt.t;max_tries : int;retry_delay : Ptime.Span.t;}'a jobis a job that can be dispatched where'ais the type of the input.
type job'= Sihl.Contract.Queue.job'={name : string;handle : string -> (unit, string) Result.t Lwt.t;failed : string -> instance -> unit Lwt.t;max_tries : int;retry_delay : Ptime.Span.t;}job'is a helper type that is used to remove the input type fromjob. Usejob'to register jobs.
val hide : 'a job -> job'hide jobreturns ajob'that can be registered with the queue service. It hides the input type of the job. Ajob'can be registered but not dispatched.
val create_job : ('a -> (unit, string) Stdlib.result Lwt.t) -> ?max_tries:int -> ?retry_delay:Ptime.span -> ?failed:(string -> instance -> unit Lwt.t) -> ('a -> string) -> (string -> ('a, string) Result.t) -> string -> 'a jobcreate_job ?max_tries ?retry_delay ?failed handle encode decode namereturns a job that can be placed on the queue (dispatched) for later processing.max_triesis the maximum times a job can fail. If a job failsmax_triesnumber of times, the status of the job becomesFailed. By default, a job can fail5times.retry_delayis the time span between two retries. By default, this value is one minute.failedis the error handler that is called whenhandlereturns an error or raises an exception. By default, this function does nothing. Usefailedto clean up resources or raise some error in a monitoring system in case a job fails.handleis the function that is called with the input when processing the job. If an exception is raised, the exception is turned intoError.encodeis called right after dispatching a job. The provided input data is encoded as string which is used for persisting the queue.decodeis called before starting to process a job.decodeturns the persisted string into the input data that is passed to the handle function.nameis the name of the job, it has to be unique among all registered jobs.
val pp_job : (Stdlib.Format.formatter -> 'a -> unit) -> Stdlib.Format.formatter -> 'a job -> unitval pp_job' : Stdlib.Format.formatter -> job' -> unitval pp_instance : Stdlib.Format.formatter -> instance -> unitval should_run : instance -> Ptime.t -> boolshould_run job nowreturns true if the queuedjobshould runnow, false if not. If a queuedjobshould run it will be processed by any idle worker as soon as possible.
module InMemory : sig ... endmodule MariaDb : sig ... endmodule PostgreSql : sig ... end