mirror of
https://git.asonix.dog/asonix/background-jobs.git
synced 2024-11-25 05:21:00 +00:00
Update docs
This commit is contained in:
parent
076a30d61c
commit
4514db49ee
2 changed files with 16 additions and 11 deletions
|
@ -1,21 +1,18 @@
|
||||||
use crate::{Job, QueueHandle};
|
use crate::{Job, QueueHandle};
|
||||||
use actix::{
|
use actix::clock::{interval_at, Duration, Instant};
|
||||||
clock::{interval_at, Duration, Instant},
|
|
||||||
Arbiter,
|
|
||||||
};
|
|
||||||
use log::error;
|
use log::error;
|
||||||
|
|
||||||
/// A type used to schedule recurring jobs.
|
/// A type used to schedule recurring jobs.
|
||||||
///
|
///
|
||||||
/// ```rust,ignore
|
/// ```rust,ignore
|
||||||
/// let server = ServerConfig::new(storage).start();
|
/// let server = create_server(storage);
|
||||||
/// every(server, Duration::from_secs(60 * 30), MyJob::new());
|
/// server.every(Duration::from_secs(60 * 30), MyJob::new());
|
||||||
/// ```
|
/// ```
|
||||||
pub fn every<J>(spawner: QueueHandle, duration: Duration, job: J)
|
pub(crate) fn every<J>(spawner: QueueHandle, duration: Duration, job: J)
|
||||||
where
|
where
|
||||||
J: Job + Clone,
|
J: Job + Clone,
|
||||||
{
|
{
|
||||||
Arbiter::spawn(async move {
|
actix::spawn(async move {
|
||||||
let mut interval = interval_at(Instant::now(), duration);
|
let mut interval = interval_at(Instant::now(), duration);
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
|
|
|
@ -13,8 +13,8 @@
|
||||||
//! ### Example
|
//! ### Example
|
||||||
//! ```rust,ignore
|
//! ```rust,ignore
|
||||||
//! use actix::System;
|
//! use actix::System;
|
||||||
//! use background_jobs::{Backoff, Job, MaxRetries, Processor, ServerConfig, WorkerConfig};
|
//! use background_jobs::{create_server, Backoff, Job, MaxRetries, Processor, WorkerConfig};
|
||||||
//! use failure::Error;
|
//! use anyhow::Error;
|
||||||
//! use serde_derive::{Deserialize, Serialize};
|
//! use serde_derive::{Deserialize, Serialize};
|
||||||
//!
|
//!
|
||||||
//! const DEFAULT_QUEUE: &'static str = "default";
|
//! const DEFAULT_QUEUE: &'static str = "default";
|
||||||
|
@ -41,7 +41,7 @@
|
||||||
//! let storage = Storage::new();
|
//! let storage = Storage::new();
|
||||||
//!
|
//!
|
||||||
//! // Start the application server. This guards access to to the jobs store
|
//! // Start the application server. This guards access to to the jobs store
|
||||||
//! let queue_handle = ServerConfig::new(storage).thread_count(8).start();
|
//! let queue_handle = create_server(storage);
|
||||||
//!
|
//!
|
||||||
//! // Configure and start our workers
|
//! // Configure and start our workers
|
||||||
//! WorkerConfig::new(move || MyState::new("My App"))
|
//! WorkerConfig::new(move || MyState::new("My App"))
|
||||||
|
@ -107,13 +107,21 @@
|
||||||
//!
|
//!
|
||||||
//! // The number of times background-jobs should try to retry a job before giving up
|
//! // The number of times background-jobs should try to retry a job before giving up
|
||||||
//! //
|
//! //
|
||||||
|
//! // This value defaults to MaxRetries::Count(5)
|
||||||
//! // Jobs can optionally override this value
|
//! // Jobs can optionally override this value
|
||||||
//! const MAX_RETRIES: MaxRetries = MaxRetries::Count(1);
|
//! const MAX_RETRIES: MaxRetries = MaxRetries::Count(1);
|
||||||
//!
|
//!
|
||||||
//! // The logic to determine how often to retry this job if it fails
|
//! // The logic to determine how often to retry this job if it fails
|
||||||
//! //
|
//! //
|
||||||
|
//! // This value defaults to Backoff::Exponential(2)
|
||||||
//! // Jobs can optionally override this value
|
//! // Jobs can optionally override this value
|
||||||
//! const BACKOFF_STRATEGY: Backoff = Backoff::Exponential(2);
|
//! const BACKOFF_STRATEGY: Backoff = Backoff::Exponential(2);
|
||||||
|
//!
|
||||||
|
//! // When should the job be considered dead
|
||||||
|
//! //
|
||||||
|
//! // The timeout defines when a job is allowed to be considered dead, and so can be retried
|
||||||
|
//! // by the job processor. The value is in milliseconds and defaults to 15,000
|
||||||
|
//! const TIMEOUT: i64 = 15_000
|
||||||
//! }
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue