job: improve docs a little

This commit is contained in:
anna 2022-12-27 01:53:13 +01:00
parent e387e43dab
commit 6e81a7198b
Signed by: fef
GPG key ID: EC22E476DC2D3D84

View file

@ -1,10 +1,10 @@
use actix_rt::Arbiter; use actix_rt::Arbiter;
use actix_web::web; use actix_web::web;
use async_trait::async_trait; use async_trait::async_trait;
use serde::{Deserialize, Serialize};
use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Weak; use std::sync::Weak;
use std::time::Duration; use std::time::Duration;
use serde::{Deserialize, Serialize};
use tokio::time::sleep; use tokio::time::sleep;
use crate::core::*; use crate::core::*;
@ -19,9 +19,15 @@ const ERROR_DELAY: Duration = Duration::from_secs(5 * 60);
/// enqueued it (which is usually a request handler). This mechanism allows /// enqueued it (which is usually a request handler). This mechanism allows
/// for fast response times to requests and automatic retries on failures /// for fast response times to requests and automatic retries on failures
/// such as network errors when a remote instance is currently offline. /// such as network errors when a remote instance is currently offline.
///
/// [`Serialize`] and [`Deserialize`] are required for two reasons:
/// Firstly, the server may be restarted between waiting for the next retry of
/// failed jobs, in which case the parameters must be stored somewhere.
/// Secondly, a future version may support executing jobs on a remote node,
/// kind of like what Sidekiq does.
#[async_trait] #[async_trait]
pub trait Job: Send + Sync + Serialize + Deserialize<'static> { pub trait Job: Send + Sync + Serialize + Deserialize<'static> {
/// Execute the errand. /// Fulfill the errand.
/// ///
/// This will be called by the scheduler in a background thread. /// This will be called by the scheduler in a background thread.
/// If the result is an error, the scheduler may retry it again later. /// If the result is an error, the scheduler may retry it again later.
@ -29,7 +35,8 @@ pub trait Job: Send + Sync + Serialize + Deserialize<'static> {
/// Return this job's name. /// Return this job's name.
/// ///
/// Currently only used for logging. /// This should be unique per type of job, like for example the name of the
/// struct implementing this trait. Currently only used for logging.
fn name(&self) -> &'static str; fn name(&self) -> &'static str;
} }