Remember how ActiveJob passes model objects to task objects?
Well, it does not matter, I remind you. Using Global ID , which in the case of the model consists of the class name and id (and the internal URL-like syntax, which is not important now).
This approach has two features.
- The task will work on the latest version of the object, at the time of launching the task, rather than adding it to the queue.
- A task may not work as intended, if an object has changed by reference between the assignment and the launch of a task.
Okay, this is actually the same feature from different angles.
It is not the object itself that is transmitted, but only a way to find it.
Transferring an object in this way after deleting its transaction is meaningless.
Do you want to transfer data and want them to come as they are, no matter what? So transfer the data. Let's say, not the object of the model itself, but the hashmap of its fields, .attributes . And before that, it would be nice to throw out too much from there using .slice (or .except ). And even then only those values that you really need from the model, positional arguments .
Otherwise, you'd better wait with the removal. For example, to make it not when servicing an HTTP request from a user, but already inside a task, informing that the deletion is about to happen, but perhaps not right now. In this case, it is possible to designate the fact that the object is awaiting deletion "with cleaning" by some flag. And even in general, you can move the entire row to another table before deleting.