queue icon indicating copy to clipboard operation
queue copied to clipboard

[17.0] [IMP] queue_job: add_depends on RetryableJobError

Open ivantodorovich opened this issue 7 months ago • 5 comments

This commit adds the posibility to add new dependencies to a job when raising a RetryableJobError.

ivantodorovich avatar Jun 06 '25 15:06 ivantodorovich

Hi @guewen, some modules you are maintaining are being modified, check this out!

OCA-git-bot avatar Jun 06 '25 15:06 OCA-git-bot

Hi! What's the use case for this? Could this be done without changing the queue_job API?

sbidoul avatar Jun 11 '25 08:06 sbidoul

Hi! What's the use case for this? Could this be done without changing the queue_job API?

Hey @sbidoul 👋🏻

The case we're implementing this for is a connector, where jobs handling the import of records identify missing record dependencies that must be imported before, and so the jobs to import such dependencies are scheduled and the current job is retried after they have succeeded

def import_sale_order(self):
    ...
    missing_products = ...
    if missing_products:
        raise RetryableJobError(
            "Missing products",
            add_depends=[
                self.with_delay().import_product(missing_product)
                for missing_product in missing_products
            ],
        )

I thought it'd be an useful addition to the API

Could this be done without changing the queue_job API?

The difficult part would be that the current transaction is rolledback, and the executing Job instance -not accessible from outside- will be stored using a separate cursor, from methods that are not easy to override. I believe @SilvioC2C tried to achieve it with https://github.com/OCA/queue/pull/758, but finally we chose another path at that time

ivantodorovich avatar Jun 11 '25 11:06 ivantodorovich

Hi @ivantodorovich , creating a new job that inserts itself in a new dependency of the current job and then retry the later which such becomes in a wait_dependencies state seems complicated and I'm afraid of all the corner cases we might encounter (job already in a graph, ...). May I suggest to handle this in the job itself ?

The code of the job method may enqueue the prerequisite job, chained with a new version of itself (same job method, same parameters), and the current job terminates, so is "done". This solution also doesn't need to handle another transaction.

guewen avatar Sep 18 '25 17:09 guewen

Admittedly if the job is already in a graph it may not do what we want neither

guewen avatar Sep 18 '25 17:09 guewen