-
-
Notifications
You must be signed in to change notification settings - Fork 470
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
[14.0] queue_job: add mixin to link jobs #573
Conversation
You can easily link jobs to their related records.
Hi @guewen, |
@guewen WDYT? |
Hey @simahawk,
This is actually doing the reverse: it links records to jobs. This is something I'd heavily discourage to do (and already did in addons reviews). Adding foreign keys on tables pointing to A job may contain metadata pointing back to records, but I'd prefer to think the jobs being only "messages" like you'd have if jobs where in a Redis queue or else. Now, if the need is about "recording" if a job has already been generated / cancelling it on actions etc., it can be handled using idempotent jobs (e.g. the job cancels itself if the action is no longer required). |
@guewen thanks for your feedback. |
I'm speaking of inserting and deleting rows in the queue_job table, which is the requirement number one and has to be as fast as possible. Operations on the table must be as fast as possible. Each index slows down operations, and conversely, FK from other tables referencing queue_job have checks to do (e.g. when you delete a job, it has to do a select on every referencing table to check cascading constraints). |
Oh, I see, you are right... |
Another concern: it (m2o or m2m) is meant to be a link from other records to show jobs (other queues using redis or whatever do not have this and are fine without btw), but then people will start to use some logic such as checking if a job exists, cancel it etc. And then you start having jobs locked by other "long" transactions that took locks / updates them when a user clicks on a button. It's really an anti-pattern when dealing with jobs, and oh boy have I seen problems with that. They must be idempotent and fire and forget. |
@guewen maybe it's time to convert the
Yes... and no. 1st of all is nice to be able to jump to specific records' jobs from their form view. Really a time saver. |
Well, the thing is that is generally considered a bad pattern in queues as you shouldn't rely on the state of others jobs. You should not need to care about 'not schedule another job' : you should enqueue it anyway and the job itself has to verify if it has to actually do something or not. I get what you are trying to address but IMO (at least on the 2nd point), that should never be necessary if the jobs are well designed and themselves check the outside state (sometimes it may require adding a state/flag on the model on which work is done). Same for this example:
Store the fact that the info was sent (using steps, state machine, you name it) on the concerned record, but do not use the job's state / existence to track the current "state of the world". A job is an asynchronous execution of a function, that's all there should be about it. If you were to use actual asynchronous python functions, you would make them store the state needed to be idempotent and be able to recover in case of reboot. I'm convinced designing jobs this way makes their usage more robust and resilient. Also more understandable (idempotency handling always in the job, not in the callers). |
As for using jsonb, yeah it makes sense in any case, but I would still discourage messing with the internals 😉 |
There hasn't been any activity on this pull request in the past 4 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days. |
You can easily link records to their related jobs
TODO