aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXinhui2016-09-28 15:43:54 +0200
committerXinhui2016-09-28 15:44:01 +0200
commit4dbfc621e34d90438095139e72e841a584b44ff7 (patch)
tree227ef09b7860e21ed8618e37ec1084c863508ec5
parentfc67bd7a40a5ab4fe8f95e0a92e76fff0200c0f4 (diff)
downloadchouette-core-4dbfc621e34d90438095139e72e841a584b44ff7.tar.bz2
Log messages of LineReferentialSync
Refs #1707
-rw-r--r--app/models/line_referential_sync.rb18
-rw-r--r--app/workers/line_referential_sync_worker.rb1
-rw-r--r--spec/models/line_referential_sync_spec.rb7
3 files changed, 19 insertions, 7 deletions
diff --git a/app/models/line_referential_sync.rb b/app/models/line_referential_sync.rb
index 67151c61e..996266b2e 100644
--- a/app/models/line_referential_sync.rb
+++ b/app/models/line_referential_sync.rb
@@ -1,6 +1,8 @@
class LineReferentialSync < ActiveRecord::Base
include AASM
belongs_to :line_referential
+ has_many :line_referential_sync_messages, :dependent => :destroy
+
after_commit :perform_sync, :on => :create
validate :multiple_process_validation, :on => :create
@@ -35,19 +37,27 @@ class LineReferentialSync < ActiveRecord::Base
end
end
+ def create_sync_message criticity, key, attributes
+ params = {
+ criticity: criticity,
+ message_key: key,
+ message_attributs: attributes
+ }
+ line_referential_sync_messages.create params
+ end
+
def log_pending
- logger.debug "#{self.class.name} sync - pending"
update_attribute(:started_at, Time.now)
+ create_sync_message :info, :pending, self.attributes
end
def log_successful
- logger.debug "#{self.class.name} sync - done"
update_attribute(:ended_at, Time.now)
+ create_sync_message :info, :successful, self.attributes
end
def log_failed error
- logger.debug e.message
- logger.debug "#{self.class.name} sync - failed"
update_attribute(:ended_at, Time.now)
+ create_sync_message :error, :failed, self.attributes.merge(error: error.message)
end
end
diff --git a/app/workers/line_referential_sync_worker.rb b/app/workers/line_referential_sync_worker.rb
index 1dbb36ad2..f5bf3b854 100644
--- a/app/workers/line_referential_sync_worker.rb
+++ b/app/workers/line_referential_sync_worker.rb
@@ -1,5 +1,6 @@
class LineReferentialSyncWorker
include Sidekiq::Worker
+ sidekiq_options :retry => false
def perform(lref_sync_id)
lref_sync = LineReferentialSync.find lref_sync_id
diff --git a/spec/models/line_referential_sync_spec.rb b/spec/models/line_referential_sync_spec.rb
index dd68b099d..38744f273 100644
--- a/spec/models/line_referential_sync_spec.rb
+++ b/spec/models/line_referential_sync_spec.rb
@@ -6,6 +6,7 @@ RSpec.describe LineReferentialSync, :type => :model do
end
it { is_expected.to belong_to(:line_referential) }
+ it { is_expected.to have_many(:line_referential_sync_messages) }
it 'should validate multiple sync instance' do
pending = create(:line_referential_sync)
@@ -25,18 +26,18 @@ RSpec.describe LineReferentialSync, :type => :model do
expect(line_referential_sync.new?).to be_truthy
end
- it 'should pending state change' do
+ it 'should log pending state change' do
expect(line_referential_sync).to receive(:log_pending)
line_referential_sync.run
end
- it 'should successful state change' do
+ it 'should log successful state change' do
expect(line_referential_sync).to receive(:log_successful)
line_referential_sync.run
line_referential_sync.successful
end
- it 'should failed state change' do
+ it 'should log failed state change' do
expect(line_referential_sync).to receive(:log_failed)
line_referential_sync.run
line_referential_sync.failed