graphile_worker_lifecycle_hooks 0.3.2

Lifecycle hooks for graphile_worker, a high performance Rust/PostgreSQL job queue
Documentation
use std::sync::Arc;
use std::time::Duration;

use chrono::{DateTime, Utc};
use graphile_worker_crontab_types::Crontab;
use graphile_worker_database::Database;
use graphile_worker_extensions::ReadOnlyExtensions;
use graphile_worker_job::Job;
use graphile_worker_job_spec::JobSpec;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ShutdownReason {
    Signal,
    Error,
    Graceful,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LocalQueueMode {
    Starting,
    Polling,
    Waiting,
    TtlExpired,
    Released,
}

#[derive(Clone)]
pub struct WorkerInitContext {
    pub database: Database,
    pub schema: String,
    pub concurrency: usize,
}

#[derive(Clone)]
pub struct WorkerStartContext {
    pub database: Database,
    pub worker_id: String,
    pub extensions: ReadOnlyExtensions,
}

#[derive(Clone)]
pub struct WorkerShutdownContext {
    pub database: Database,
    pub worker_id: String,
    pub reason: ShutdownReason,
}

#[derive(Clone)]
pub struct JobFetchContext {
    pub job: Arc<Job>,
    pub worker_id: String,
}

#[derive(Clone)]
pub struct JobStartContext {
    pub job: Arc<Job>,
    pub worker_id: String,
}

#[derive(Clone)]
pub struct JobCompleteContext {
    pub job: Arc<Job>,
    pub worker_id: String,
    pub duration: Duration,
}

#[derive(Clone)]
pub struct JobFailContext {
    pub job: Arc<Job>,
    pub worker_id: String,
    pub error: String,
    pub will_retry: bool,
}

#[derive(Clone)]
pub struct JobPermanentlyFailContext {
    pub job: Arc<Job>,
    pub worker_id: String,
    pub error: String,
}

#[derive(Clone)]
pub struct BeforeJobRunContext {
    pub job: Arc<Job>,
    pub worker_id: String,
    pub payload: serde_json::Value,
}

#[derive(Clone)]
pub struct AfterJobRunContext {
    pub job: Arc<Job>,
    pub worker_id: String,
    pub result: Result<(), String>,
    pub duration: Duration,
}

#[derive(Clone)]
pub struct CronTickContext {
    pub timestamp: DateTime<Utc>,
    pub crontabs: Vec<Crontab>,
}

#[derive(Clone)]
pub struct CronJobScheduledContext {
    pub crontab: Crontab,
    pub scheduled_at: DateTime<Utc>,
}

#[derive(Clone)]
pub struct BeforeJobScheduleContext {
    pub identifier: String,
    pub payload: serde_json::Value,
    pub spec: JobSpec,
}

#[derive(Debug, Clone)]
pub struct LocalQueueInitContext {
    pub worker_id: String,
}

#[derive(Debug, Clone)]
pub struct LocalQueueSetModeContext {
    pub worker_id: String,
    pub old_mode: LocalQueueMode,
    pub new_mode: LocalQueueMode,
}

#[derive(Debug, Clone)]
pub struct LocalQueueGetJobsCompleteContext {
    pub worker_id: String,
    pub jobs_count: usize,
}

#[derive(Debug, Clone)]
pub struct LocalQueueReturnJobsContext {
    pub worker_id: String,
    pub jobs_count: usize,
}

#[derive(Debug, Clone)]
pub struct LocalQueueRefetchDelayStartContext {
    pub worker_id: String,
    pub duration: Duration,
    pub threshold: usize,
    pub abort_threshold: usize,
}

#[derive(Debug, Clone)]
pub struct LocalQueueRefetchDelayAbortContext {
    pub worker_id: String,
    pub count: usize,
    pub abort_threshold: usize,
}

#[derive(Debug, Clone)]
pub struct LocalQueueRefetchDelayExpiredContext {
    pub worker_id: String,
}