aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorXinhui2016-09-26 17:15:46 +0200
committerXinhui2016-09-27 10:56:48 +0200
commit8c378fe9c6299ac9400ff6898702b7e0c6a64799 (patch)
tree89bd93e6bc2e5d4752020c599e1b479a89b3c1c7 /app
parent56c51faf52b824afd2057194233f357e8d5330ae (diff)
downloadchouette-core-8c378fe9c6299ac9400ff6898702b7e0c6a64799.tar.bz2
Wip gem sidekiq && LineReferentialSyncWorker
Refs #1707
Diffstat (limited to 'app')
-rw-r--r--app/models/line_referential_sync.rb9
-rw-r--r--app/workers/line_referential_sync_worker.rb19
2 files changed, 23 insertions, 5 deletions
diff --git a/app/models/line_referential_sync.rb b/app/models/line_referential_sync.rb
index 763936f3b..35e074d4e 100644
--- a/app/models/line_referential_sync.rb
+++ b/app/models/line_referential_sync.rb
@@ -1,10 +1,9 @@
class LineReferentialSync < ActiveRecord::Base
belongs_to :line_referential
+ after_create :synchronize
- has_many :line_sync_operations, dependent: :destroy
-
- def record_status status, message
- line_sync_operations << LineSyncOperation.new(status: status, message: message)
- line_sync_operations.first.destroy while line_sync_operations.count > 30
+ private
+ def synchronize
+ LineReferentialSyncWorker.perform_async(self.id)
end
end
diff --git a/app/workers/line_referential_sync_worker.rb b/app/workers/line_referential_sync_worker.rb
new file mode 100644
index 000000000..719a10190
--- /dev/null
+++ b/app/workers/line_referential_sync_worker.rb
@@ -0,0 +1,19 @@
+class LineReferentialSyncWorker
+ include Sidekiq::Worker
+
+ def update_started_at lref_sync
+ lref_sync.update_attribute(:started_at, Time.now)
+
+ end
+
+ def perform(lref_sync_id)
+ lref_sync = LineReferentialSync.find lref_sync_id
+
+ begin
+ Stif::CodifLineSynchronization.synchronize
+ lref_sync.update_attribute(:ended_at, Time.now)
+ rescue Exception => e
+ ap 'call to rescue Exception'
+ end
+ end
+end