Skip to content

Idiomatic way to handle error for each NamedJob? #50

@qwfy

Description

@qwfy

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions