aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXinhui2016-09-27 15:49:04 +0200
committerXinhui2016-09-27 16:01:47 +0200
commit2d6fa24975ac5a3d28e657a96a781db1cb17d56c (patch)
tree66101505db30cd3100fbba63bf13d4cbcf4f4990
parent12f506a82ae9099cface5b9507dd8a36bf923508 (diff)
downloadchouette-core-2d6fa24975ac5a3d28e657a96a781db1cb17d56c.tar.bz2
Refactoring rake codifligne:sync
Refs #1707
-rw-r--r--app/models/line_referential_sync.rb2
-rw-r--r--app/workers/line_referential_sync_worker.rb4
-rw-r--r--lib/tasks/codifligne.rake5
-rw-r--r--spec/models/line_referential_sync_spec.rb2
4 files changed, 9 insertions, 4 deletions
diff --git a/app/models/line_referential_sync.rb b/app/models/line_referential_sync.rb
index c0af54ac1..783fceaba 100644
--- a/app/models/line_referential_sync.rb
+++ b/app/models/line_referential_sync.rb
@@ -1,6 +1,6 @@
class LineReferentialSync < ActiveRecord::Base
belongs_to :line_referential
- after_create :perform_sync
+ after_commit :perform_sync, :on => :create
validate :multiple_process_validation, :on => :create
private
diff --git a/app/workers/line_referential_sync_worker.rb b/app/workers/line_referential_sync_worker.rb
index e63bf97cc..b39fae5e5 100644
--- a/app/workers/line_referential_sync_worker.rb
+++ b/app/workers/line_referential_sync_worker.rb
@@ -1,6 +1,5 @@
class LineReferentialSyncWorker
include Sidekiq::Worker
- sidekiq_options :retry => false
def update_started_at lref_sync
lref_sync.update_attribute(:started_at, Time.now)
@@ -11,13 +10,16 @@ class LineReferentialSyncWorker
end
def perform(lref_sync_id)
+ logger.info "worker call to perfom"
lref_sync = LineReferentialSync.find lref_sync_id
update_started_at lref_sync
begin
Stif::CodifLineSynchronization.synchronize
+ logger.info "worker done CodifLineSynchronization"
rescue Exception => e
ap "LineReferentialSyncWorker perform:rescue #{e.message}"
ensure
+ logger.info "worker ensure ended_at"
update_ended_at lref_sync
end
end
diff --git a/lib/tasks/codifligne.rake b/lib/tasks/codifligne.rake
index 8b7a4f669..f306ee484 100644
--- a/lib/tasks/codifligne.rake
+++ b/lib/tasks/codifligne.rake
@@ -1,6 +1,9 @@
namespace :codifligne do
desc "Sync lines, companies, networks, and group of lines from codifligne"
task sync: :environment do
- Stif::CodifLineSynchronization.synchronize
+ lref = LineReferential.find_by(name: 'CodifLigne')
+ lref_sync = LineReferentialSync.create(line_referential: lref)
+ raise "Codifligne:sync aborted - an sync is already running" unless lref_sync.valid?
+ lref_sync.save if lref_sync.valid?
end
end
diff --git a/spec/models/line_referential_sync_spec.rb b/spec/models/line_referential_sync_spec.rb
index f5c738792..bcd58f0c9 100644
--- a/spec/models/line_referential_sync_spec.rb
+++ b/spec/models/line_referential_sync_spec.rb
@@ -14,6 +14,6 @@ RSpec.describe LineReferentialSync, :type => :model do
it 'should call LineReferentialSyncWorker on create' do
expect(LineReferentialSyncWorker).to receive(:perform_async)
- create :line_referential_sync
+ create(:line_referential_sync).run_callbacks(:commit)
end
end