Skip to content

Introducing: Batched Journaling!

Compare
Choose a tag to compare
@smudge smudge released this 23 Aug 22:49
· 6 commits to master since this release
4ff34a6

This adds transactional batching to journaled. What does that mean? Well, now, by default, when multiple events are emitted inside of a transaction:

ActiveRecord::Base.transaction do
  event_1.journal!
  event_2.journal!
end

A single job will be enqueued directly before the SQL COMMIT statement, batching up the two events. (And if the transaction rolls back, the job will never be enqueued.)

This behavior can be disabled with a global config, but may become permanent in future versions:

Journaled.transactional_batching_enabled = !Rails.env.production?

What happens if we aren't in a transaction? Well, the same thing that happened before! (A job will be enqueued right away.) In future, we may introduce safety checks to warn you if you are attempting to journal events outside of a transactional context.

Because this bumps the version to 5.0, it also removes compatibility for Journaled::DeliveryJob jobs enqueued with legacy (3.1.0-era) arguments. This job now accepts a list of events to emit, rather than a single event-kwarg-blog, so a new legacy input pattern is accepted for compatibility with jobs enqueued by v4.x.x of the gem.