Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Idiomatic way to handle error for each NamedJob? #50

Open
qwfy opened this issue Dec 10, 2023 · 0 comments
Open

Idiomatic way to handle error for each NamedJob? #50

qwfy opened this issue Dec 10, 2023 · 0 comments

Comments

@qwfy
Copy link
Contributor

qwfy commented Dec 10, 2023

Thanks for the awesome library.

I see that you can set an error handler for each JobRegistry, I'm wondering what's the idiomatic way to handle error for each NamedJob, it cannot be done on the error handler of JobRegistry, since the function signature does not have CurrentJob (you can wrap it in the error, but that's not ergonomic).

One way to do this: (very rough draft)

#[job(
    name = "...",
    error_handler = my_error_handler
)]
async fn my_job(...)

async fn my_error_handler(
    tx: DbTransaction,
    current_job: _, 
    err: SomeError,
    is_error_final: bool    // Is this the last attempt for this job?
) -> Result<....> {
    ...
}

Another way: (very rough draft)

#[job(
    name = "...",
)]
async fn my_job(
    current_job: _,
    times_already_tried: u32,
    total_allowed_tries: u32,
) -> Result<()> {
    if times_already_tried >= total_allowed_tries {
        // do something to handle the error,
        // this implies that total_allowed_tries is not enforced by sqlxmq
        current_job.complete().await?;
    }
}

Any thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant