Examples:
# HTTP calls within transaction
User.transaction do
  user = User.new(user_params)
  user.save!
  # HTTP API call
  PaymentsService.charge!(user)
end
#=> raises Isolator::HTTPError
# background job
User.transaction do
  user.update!(confirmed_at: Time.now)
  UserMailer.successful_confirmation(user).deliver_later
end
#=> raises Isolator::BackgroundJobErrorOf course, Isolator can detect implicit transactions too. Consider this pretty common bad practice—enqueueing background job from after_create callback:
class Comment < ApplicationRecord
  # the good way is to use after_create_commit
  # (or not use callbacks at all)
  after_create :notify_author
  private
  def notify_author
    CommentMailer.comment_created(self).deliver_later
  end
end
Comment.create(text: "Mars is watching you!")
#=> raises Isolator::BackgroundJobErrorIsolator is supposed to be used in tests and on staging.



