diff --git a/crates/ctx/src/lib.rs b/crates/ctx/src/lib.rs index 692b2cc..2c6a649 100644 --- a/crates/ctx/src/lib.rs +++ b/crates/ctx/src/lib.rs @@ -1,3 +1,5 @@ +use std::fmt::Debug; + use getset::Getters; use graphile_worker_extensions::ReadOnlyExtensions; use graphile_worker_job::Job; @@ -7,14 +9,20 @@ use sqlx::PgPool; #[derive(Getters, Clone, Debug)] #[getset(get = "pub")] pub struct WorkerContext { + /// The payload of the job. payload: Value, + /// The postgres pool. pg_pool: PgPool, + /// The job. job: Job, + /// The worker id. worker_id: String, + /// Extensions (for providing custom app state) extensions: ReadOnlyExtensions, } impl WorkerContext { + /// Creates a new WorkerContext. pub fn new( payload: Value, pg_pool: PgPool, @@ -30,4 +38,9 @@ impl WorkerContext { extensions, } } + + /// Returns the extension value associated with the specified type. + pub fn get_ext(&self) -> Option<&T> { + self.extensions.get() + } }