2018-04-26 08:55:53 +00:00
|
|
|
require_dependency 'sequencer/unit/import/common/model/mixin/handle_failure'
|
2017-08-14 11:56:23 +00:00
|
|
|
|
|
|
|
class Sequencer
|
|
|
|
class Unit
|
|
|
|
module Import
|
|
|
|
module Common
|
|
|
|
module Model
|
|
|
|
class Save < Sequencer::Unit::Base
|
2018-08-15 10:05:54 +00:00
|
|
|
prepend ::Sequencer::Unit::Import::Common::Model::Mixin::Skip::Action
|
2017-08-14 11:56:23 +00:00
|
|
|
include ::Sequencer::Unit::Import::Common::Model::Mixin::HandleFailure
|
|
|
|
|
2018-08-15 10:05:54 +00:00
|
|
|
uses :instance, :action, :dry_run
|
2017-08-30 15:16:27 +00:00
|
|
|
provides :instance
|
2017-08-14 11:56:23 +00:00
|
|
|
|
2018-08-15 10:05:54 +00:00
|
|
|
skip_action :skipped, :failed, :unchanged
|
|
|
|
|
2017-08-14 11:56:23 +00:00
|
|
|
def process
|
|
|
|
return if dry_run
|
|
|
|
return if instance.blank?
|
|
|
|
instance.save!
|
|
|
|
rescue => e
|
|
|
|
handle_failure(e)
|
2017-08-30 15:16:27 +00:00
|
|
|
|
|
|
|
# unset instance if something went wrong
|
|
|
|
state.provide(:instance, nil)
|
2017-08-14 11:56:23 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|