Any way to get finsihed jobs? #340
-
Hey, I have an axum server that deploys jobs to different kinds of microservices. All it basically does is send jobs to the microservices and wait do other stuff in the meanwhile. Then once it has finished I want it to check up on the job I have dispatched to the microservice. |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 19 replies
-
All storage have a `fetch_by_id` method. It should give you the updated
version of a job.
…On Mon, 1 Jul 2024 at 10:12, hldup ***@***.***> wrote:
Hey, I have an axum server that deploys jobs to different kinds of
microservices. All it basically does is send jobs to the microservices and
wait do other stuff in the meanwhile. Then once it has finished I want it
to check up on the job I have dispatched to the microservice.
Is there a function or any way to query the RedisStorage to check if a job
has finished?
—
Reply to this email directly, view it on GitHub
<#340>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AWXVRGQO2BP4KCCZJDELLPDZKD6PFAVCNFSM6AAAAABKE6P6DGVHI2DSMVQWIX3LMV43ERDJONRXK43TNFXW4OZWHA4DINJWG4>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
I have made a basic wrapper function that executes a trait function that is implemented to a struct that implements apalis::prelude::Job. main.rs Monitor::<TokioExecutor>::new()
.register_with_count(4, {
WorkerBuilder::new("edit-runner")
.layer(TraceLayer::new())
.with_storage(storage.clone())
.data(state.clone())
.build_fn(jobhandler::run_job::<EditorJob, State>)
})
.run()
.await
.unwrap(); jobhandler::run_job() pub async fn run_job<T, S>(mut job: T, state: Data<S>)
where
T: Serialize + DeserializeOwned + Send + 'static + Unpin + Job + Sync + JobRunner<T, S>,
S: StateHandler,
{
match job.run(state).await {
Ok(_) => {
log::debug!("Job has finished ok");
job.set_status(JobStatus::Ok)
}
Err(error) => {
log::error!("job has failed");
job.set_status(JobStatus::Error("failed".into()))
}
};
} job.rs impl JobRunner<EditorJob, crate::State> for EditorJob {
async fn run(&mut self, state: Data<crate::State>) -> Result<(), jobhandler::JobError> {
thread::sleep(Duration::from_secs(35));
Ok(())
}
fn set_status(&mut self, status: jobhandler::JobStatus) {
self.set_status(status);
}
fn get_status(&self) -> jobhandler::JobStatus {
self.status().to_owned()
}
} |
Beta Was this translation helpful? Give feedback.
-
Does fetch_with_id + update work for you? |
Beta Was this translation helpful? Give feedback.
-
Is there an easy way to decode last_error back to Result<T,String> ? |
Beta Was this translation helpful? Give feedback.
-
I tried the following and it worked for me: In layers.rs:
if I convert the ok result to a serde_json::Value,instead of format!({ok:?}):
and then in my own code, check last_error for a an option value, json decode the value back into a Result<MyType,String> and it works. |
Beta Was this translation helpful? Give feedback.
-
Here is a changeset that is working for me (sqlite only right now) and currently has a couple of unwraps: |
Beta Was this translation helpful? Give feedback.
Its still WIP, I need to incorporate the result part. You could pull it manually if needed.