OCA / queue

Asynchronous Job Queue

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[14.0] identity_exact not working w/ chained jobs?

simahawk opened this issue · comments

I have this piece of code

        for rec in new_records:
            job1 = rec.delayable().action_exchange_generate()
            if not skip_send:
                # Chain send job
                job1.on_done(rec.delayable().action_exchange_send())
            job1.delay()

I inject identity_key=identity_exact here.

Here I test that no duplicated job gets created but it does not work.

    def test_job(self):
        with trap_jobs() as trap:
            self.backend._check_output_exchange_sync(record_ids=self.record.ids)
            trap.assert_jobs_count(2)
            trap.assert_enqueued_job(
                self.backend.exchange_record_model.action_exchange_generate,
            )
            trap.assert_enqueued_job(
                self.backend.exchange_record_model.action_exchange_send,
            )
            self.backend._check_output_exchange_sync(record_ids=self.record.ids)
            self.backend._check_output_exchange_sync(record_ids=self.record.ids)
            # identity key should prevent having new jobs
            trap.assert_jobs_count(2)

I have 6 jobs at the end while I expect to have still 2 jobs only.

I've inspected the identity keys of those jobs and they all match 🤔
I also checked if job.job_record_with_same_identity_key gets called: it is called but it cannot find the jobs.
Flushing does not help.

I've created a silly server action to test the same piece of code via UI on the same record and gives me the same result...

Am I doing something wrong or we have a bug w/ chained jobs?

Side note: unless I'm mistaken I think job.job_record_with_same_identity_key does not search for all possible states when you have a job that is waiting for a dependency here

("state", "in", [PENDING, ENQUEUED]),

I confirm that by removing the chain from the equation, it works:

job1 = rec.delayable().action_exchange_generate()
job1.delay()

This works fine in my server action and no extra job gets created.
At first sight I don't see why it shouldn't work w/ chained jobs.
@guewen any pointer?

Hi @simahawk, looks like #546?

Ciao @guewen 👋 Ahhh! I missed that, thanks!

@guewen in regards to #546 I'm not sure this change will solve the problem. What I see is that - in my case - both jobs are re-created, not only the one that is waiting. Which means that just adding WAIT_DEPENDENCIES won't be enough.
Am I wrong?

I would need to dive into the implementation and I won't be able now 😔

IIRC the idea was that identity keys on a graph is an all or nothing thing: if all the keys are identical, then the whole graph is discarded. Otherwise the graph is enqueued.

Hope that helps

There hasn't been any activity on this issue in the past 6 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days.
If you want this issue to never become stale, please ask a PSC member to apply the "no stale" label.