Skip to content
  • Jean Boussier's avatar
    e922c592
    Implement Active Job enqueue_after_transaction_commit · e922c592
    Jean Boussier authored
    
    
    A fairly common mistake with Rails is to enqueue a job from inside a
    transaction, with a record as argumemnt, which then lead to a RecordNotFound
    error when picked up by the queue.
    
    This is even one of the arguments advanced for job runners backed by the
    database such as `solid_queue`, `delayed_job` or `good_job`.
    
    But relying on this is undesirable in my opinion as it makes the Active Job
    abstraction leaky, and if in the future you need to migrate to another backend
    or even just move the queue to a separate database, you may experience a lot of
    race conditions of the sort.
    
    To resolve this problem globally, we can make Active Job optionally transaction
    aware, and automatically defer job queueing to `after_commit`.
    
    Co-Authored-By: default avatarCristian Bica <cristian.bica@gmail.com>
    e922c592
    Implement Active Job enqueue_after_transaction_commit
    Jean Boussier authored
    
    
    A fairly common mistake with Rails is to enqueue a job from inside a
    transaction, with a record as argumemnt, which then lead to a RecordNotFound
    error when picked up by the queue.
    
    This is even one of the arguments advanced for job runners backed by the
    database such as `solid_queue`, `delayed_job` or `good_job`.
    
    But relying on this is undesirable in my opinion as it makes the Active Job
    abstraction leaky, and if in the future you need to migrate to another backend
    or even just move the queue to a separate database, you may experience a lot of
    race conditions of the sort.
    
    To resolve this problem globally, we can make Active Job optionally transaction
    aware, and automatically defer job queueing to `after_commit`.
    
    Co-Authored-By: default avatarCristian Bica <cristian.bica@gmail.com>
Loading