pub struct WebhookContext {
pub webhook_name: String,
pub request_id: String,
pub idempotency_key: Option<String>,
/* private fields */
}Expand description
Context available to webhook handlers.
Fields§
§webhook_name: StringWebhook name.
request_id: StringUnique request ID for this webhook invocation.
idempotency_key: Option<String>Idempotency key if extracted from request.
Implementations§
Source§impl WebhookContext
impl WebhookContext
Sourcepub fn new(
webhook_name: String,
request_id: String,
headers: HashMap<String, String>,
db_pool: PgPool,
http_client: Client,
) -> Self
pub fn new( webhook_name: String, request_id: String, headers: HashMap<String, String>, db_pool: PgPool, http_client: Client, ) -> Self
Create a new webhook context.
Sourcepub fn with_idempotency_key(self, key: Option<String>) -> Self
pub fn with_idempotency_key(self, key: Option<String>) -> Self
Set idempotency key.
Sourcepub fn with_job_dispatch(self, dispatcher: Arc<dyn JobDispatch>) -> Self
pub fn with_job_dispatch(self, dispatcher: Arc<dyn JobDispatch>) -> Self
Set job dispatcher.
Sourcepub fn with_env_provider(self, provider: Arc<dyn EnvProvider>) -> Self
pub fn with_env_provider(self, provider: Arc<dyn EnvProvider>) -> Self
Set environment provider.
Sourcepub fn header(&self, name: &str) -> Option<&str>
pub fn header(&self, name: &str) -> Option<&str>
Get a request header value.
Header names are case-insensitive.
Sourcepub async fn dispatch_job<T: Serialize>(
&self,
job_type: &str,
args: T,
) -> Result<Uuid>
pub async fn dispatch_job<T: Serialize>( &self, job_type: &str, args: T, ) -> Result<Uuid>
Dispatch a background job for async processing.
This is the recommended way to handle webhook events:
- Validate the webhook signature
- Dispatch a job to process the event
- Return 202 Accepted immediately
§Arguments
job_type- The registered name of the job typeargs- The arguments for the job (will be serialized to JSON)
§Returns
The UUID of the dispatched job, or an error if dispatch is not available.
Trait Implementations§
Source§impl EnvAccess for WebhookContext
impl EnvAccess for WebhookContext
Source§fn env_provider(&self) -> &dyn EnvProvider
fn env_provider(&self) -> &dyn EnvProvider
Get the environment provider.
Source§fn env_or(&self, key: &str, default: &str) -> String
fn env_or(&self, key: &str, default: &str) -> String
Get an environment variable with a default value. Read more
Source§fn env_require(&self, key: &str) -> Result<String>
fn env_require(&self, key: &str) -> Result<String>
Get a required environment variable. Read more
Source§fn env_parse<T: FromStr>(&self, key: &str) -> Result<T>
fn env_parse<T: FromStr>(&self, key: &str) -> Result<T>
Get an environment variable and parse it to the specified type. Read more
Source§fn env_parse_or<T: FromStr>(&self, key: &str, default: T) -> Result<T>
fn env_parse_or<T: FromStr>(&self, key: &str, default: T) -> Result<T>
Get an environment variable and parse it, with a default. Read more
Source§fn env_contains(&self, key: &str) -> bool
fn env_contains(&self, key: &str) -> bool
Check if an environment variable is set.
Auto Trait Implementations§
impl Freeze for WebhookContext
impl !RefUnwindSafe for WebhookContext
impl Send for WebhookContext
impl Sync for WebhookContext
impl Unpin for WebhookContext
impl !UnwindSafe for WebhookContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more