Created
December 2, 2015 08:04
-
-
Save mainameiz/789698ae15ecf809a73f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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