Struct brokkr::Worker[][src]

pub struct Worker<'a, T: Perform + Clone> { /* fields omitted */ }

Worker process.

The worker is responsible for consuming a single queue and processing tasks as they become available. It will will register itself with the backend and send regular status update for monitoring.

The worker itself does not take care of concurrency. In order to process multiple tasks on the same machines you need to start multiple worker processes yourself.

Usage

use std::time::Duration;
use brokkr::{Brokkr, Worker, Perform};

#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone)]
struct Task {
  name: String
}

#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
struct TaskResult;

impl Perform for Task {
  type Result = String;
  type Error = ();
  type Context = ();

  fn process(&self, _: &Self::Context) -> Result<Self::Result, Self::Error> {
    Ok(format!("Done: {}", self.name).to_owned())
  }
}

let brokkr = Brokkr::new("default".into());

let worker: Worker<Task> = Worker::new(
  &brokkr,
  (),
  Duration::from_millis(500),
  Duration::from_secs(10),
);

worker.process_many(Duration::from_secs(1));

Methods

impl<'a, T: Perform + Clone> Worker<'a, T>
[src]

Create a worker process.

Arguments

  • brokkr - The broker to use to communicate with the Redis backend.
  • ctx - Context object. Use this for things which have costly initialization but should be available to all tasks during procssing.
  • timeout - Job timeout. All tasks taking more than this duration to process will be marked as failed.
  • result_ttl - Job result ttl.

Process a single task from the queue and exit. Exits immediatly if the queue is empty.

Use this to build your own processing loop if process_many doesn't fit.

Process tasks in a loop by polling the queue every wait_timeout ms.

Arguments

  • wait_timeout - Timeout in ms to wait between polls to the queue.

Trait Implementations

impl<'a, T: Perform + Clone> Drop for Worker<'a, T>
[src]

Executes the destructor for this type. Read more

Auto Trait Implementations

impl<'a, T> !Send for Worker<'a, T>

impl<'a, T> !Sync for Worker<'a, T>