Skip to content

Instantly share code, notes, and snippets.

@mainameiz
Created December 2, 2015 08:04
Show Gist options
  • Save mainameiz/789698ae15ecf809a73f to your computer and use it in GitHub Desktop.
Save mainameiz/789698ae15ecf809a73f to your computer and use it in GitHub Desktop.
class Quest::SyncToCoreAction < Quest::BaseAction
validates :quest, presence: true
# Minimal implementation of class (like AR model) that can hold transaction callbacks.
class FakeModel
def initialize(quest_id)
@quest_id = quest_id
end
def has_transactional_callbacks?
true
end
def committed!
QuestToCoreSynchronizer.perform_async(@quest_id)
end
end
private
def execute
record = FakeModel.new(quest.id)
if ActiveRecord::Base.connection.transaction_open?
ActiveRecord::Base.connection.current_transaction.add_record(record)
else
record.committed!
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment