mirror of
https://git.asonix.dog/asonix/background-jobs.git
synced 2024-11-22 03:51:00 +00:00
Fix jobs-server
This commit is contained in:
parent
d266315f1f
commit
a22d10242a
5 changed files with 25 additions and 19 deletions
|
@ -1 +1 @@
|
||||||
RUST_LOG=server_jobs_example=info
|
RUST_LOG=info
|
||||||
|
|
|
@ -184,10 +184,6 @@ impl JobInfo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn is_failed(&self) -> bool {
|
|
||||||
self.status == JobStatus::Failed
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn needs_retry(&mut self) -> bool {
|
pub fn needs_retry(&mut self) -> bool {
|
||||||
let should_retry = self.is_failed() && self.increment().should_requeue();
|
let should_retry = self.is_failed() && self.increment().should_requeue();
|
||||||
|
|
||||||
|
@ -207,6 +203,14 @@ impl JobInfo {
|
||||||
self.status == JobStatus::Pending
|
self.status == JobStatus::Pending
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_failed(&self) -> bool {
|
||||||
|
self.status == JobStatus::Failed
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_finished(&self) -> bool {
|
||||||
|
self.status == JobStatus::Finished
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn is_in_queue(&self, queue: &str) -> bool {
|
pub(crate) fn is_in_queue(&self, queue: &str) -> bool {
|
||||||
self.queue == queue
|
self.queue == queue
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,8 +36,8 @@ use crate::server::{coerce, Config};
|
||||||
#[derive(Clone, Debug, Deserialize)]
|
#[derive(Clone, Debug, Deserialize)]
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
enum EitherJob {
|
enum EitherJob {
|
||||||
New(NewJobInfo),
|
|
||||||
Existing(JobInfo),
|
Existing(JobInfo),
|
||||||
|
New(NewJobInfo),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) struct PullConfig {
|
pub(crate) struct PullConfig {
|
||||||
|
@ -135,6 +135,16 @@ fn store_job(
|
||||||
EitherJob::Existing(job) => job,
|
EitherJob::Existing(job) => job,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if job.is_pending() {
|
||||||
|
info!("Storing pending job, {}", job.id());
|
||||||
|
}
|
||||||
|
if job.is_finished() {
|
||||||
|
info!("Finished job {}", job.id());
|
||||||
|
}
|
||||||
|
if job.is_failed() {
|
||||||
|
info!("Job failed {}", job.id());
|
||||||
|
}
|
||||||
|
|
||||||
storage.store_job(job, server_id).map_err(Error::from)
|
storage.store_job(job, server_id).map_err(Error::from)
|
||||||
})
|
})
|
||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
|
|
|
@ -151,7 +151,7 @@ fn fetch_queue(
|
||||||
server_id: usize,
|
server_id: usize,
|
||||||
) -> Result<Vec<JobInfo>, Error> {
|
) -> Result<Vec<JobInfo>, Error> {
|
||||||
storage
|
storage
|
||||||
.stage_jobs(100, queue, server_id)
|
.stage_jobs(10, queue, server_id)
|
||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,6 @@ where
|
||||||
{
|
{
|
||||||
pull: Pull,
|
pull: Pull,
|
||||||
push: Push,
|
push: Push,
|
||||||
push2: Push,
|
|
||||||
push_address: String,
|
push_address: String,
|
||||||
pull_address: String,
|
pull_address: String,
|
||||||
queue: String,
|
queue: String,
|
||||||
|
@ -75,7 +74,6 @@ where
|
||||||
|
|
||||||
let Worker {
|
let Worker {
|
||||||
push,
|
push,
|
||||||
push2,
|
|
||||||
pull,
|
pull,
|
||||||
push_address: _,
|
push_address: _,
|
||||||
pull_address: _,
|
pull_address: _,
|
||||||
|
@ -85,12 +83,13 @@ where
|
||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
let (tx, rx) = channel(5);
|
let (tx, rx) = channel(5);
|
||||||
|
let tx2 = tx.clone();
|
||||||
|
|
||||||
tokio::spawn(
|
tokio::spawn(
|
||||||
rx.map_err(|_| RecvError)
|
rx.map_err(|_| RecvError)
|
||||||
.from_err::<Error>()
|
.from_err::<Error>()
|
||||||
.and_then(serialize_request)
|
.and_then(serialize_request)
|
||||||
.forward(push2.sink(1))
|
.forward(push.sink(1))
|
||||||
.map(|_| ())
|
.map(|_| ())
|
||||||
.or_else(|_| Ok(())),
|
.or_else(|_| Ok(())),
|
||||||
);
|
);
|
||||||
|
@ -101,8 +100,7 @@ where
|
||||||
.and_then(parse_multipart)
|
.and_then(parse_multipart)
|
||||||
.and_then(move |job| report_running(job, tx.clone()))
|
.and_then(move |job| report_running(job, tx.clone()))
|
||||||
.and_then(move |job| process_job(job, &processors))
|
.and_then(move |job| process_job(job, &processors))
|
||||||
.and_then(serialize_request)
|
.forward(tx2)
|
||||||
.forward(push.sink(1))
|
|
||||||
.map(move |_| info!("worker for queue {} is shutting down", queue))
|
.map(move |_| info!("worker for queue {} is shutting down", queue))
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
error!("Error processing job, {}", e);
|
error!("Error processing job, {}", e);
|
||||||
|
@ -152,20 +150,14 @@ where
|
||||||
Push::builder(self.context.clone())
|
Push::builder(self.context.clone())
|
||||||
.connect(&self.push_address)
|
.connect(&self.push_address)
|
||||||
.build()
|
.build()
|
||||||
.join(
|
|
||||||
Push::builder(self.context.clone())
|
|
||||||
.connect(&self.push_address)
|
|
||||||
.build(),
|
|
||||||
)
|
|
||||||
.join(
|
.join(
|
||||||
Pull::builder(self.context.clone())
|
Pull::builder(self.context.clone())
|
||||||
.connect(&self.pull_address)
|
.connect(&self.pull_address)
|
||||||
.build(),
|
.build(),
|
||||||
)
|
)
|
||||||
.map(|((push, push2), pull)| {
|
.map(|(push, pull)| {
|
||||||
let config = Worker {
|
let config = Worker {
|
||||||
push,
|
push,
|
||||||
push2,
|
|
||||||
pull,
|
pull,
|
||||||
push_address: self.push_address,
|
push_address: self.push_address,
|
||||||
pull_address: self.pull_address,
|
pull_address: self.pull_address,
|
||||||
|
|
Loading…
Reference in a new issue