Struct background_jobs::SpawnerConfig
source · pub struct SpawnerConfig { /* private fields */ }
Expand description
SpawnerConfig is the only part of this library required to actually exist in your application.
This type is used to queue new jobs into the background-jobs
server.
ⓘ
let spawner = SpawnerConfig::new("localhost", 5555);
tokio::spawn(
spawner
.queue::<MyProcessor>(job)
.map_err(|_| ()),
);
Implementations§
source§impl SpawnerConfig
impl SpawnerConfig
sourcepub fn new(server_host: &str, base_port: usize) -> SpawnerConfig
pub fn new(server_host: &str, base_port: usize) -> SpawnerConfig
Create a SpawnerConfig
server_host
is the hostname or IP address of the host that the server is running onbase_port
is the samebase_port
from the server config. The spawner will only ever need to communicate overbase_port
sourcepub fn new_with_context(
server_host: &str,
base_port: usize,
ctx: Arc<Context>
) -> SpawnerConfig
pub fn new_with_context(
server_host: &str,
base_port: usize,
ctx: Arc<Context>
) -> SpawnerConfig
The same as SpawnerConfig::new()
, but with a provided ZeroMQ Context.
This can be useful if you have other uses of ZeroMQ in your application, and want to share a context with your dependencies.
If you’re running the Server, Worker, and Spawner in the same application, you should share a ZeroMQ context between them.
sourcepub fn queue<P>(
&self,
job: <P as Processor<()>>::Job
) -> impl Future<Item = (), Error = Error>where
P: Processor<()>,
pub fn queue<P>(
&self,
job: <P as Processor<()>>::Job
) -> impl Future<Item = (), Error = Error>where
P: Processor<()>,
Queue a job to be executed in the background
sourcepub fn queue_sync<P>(&self, job: <P as Processor<()>>::Job) -> Result<(), Error>where
P: Processor<()>,
pub fn queue_sync<P>(&self, job: <P as Processor<()>>::Job) -> Result<(), Error>where
P: Processor<()>,
queue_sync
is the same as Queue, except that it blocks the current thread while it is
sending the message to the jobs server.
If you have a tokio-based application, you should use queue
instead.