aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXinhui2016-09-26 17:15:46 +0200
committerXinhui2016-09-27 10:56:48 +0200
commit8c378fe9c6299ac9400ff6898702b7e0c6a64799 (patch)
tree89bd93e6bc2e5d4752020c599e1b479a89b3c1c7
parent56c51faf52b824afd2057194233f357e8d5330ae (diff)
downloadchouette-core-8c378fe9c6299ac9400ff6898702b7e0c6a64799.tar.bz2
Wip gem sidekiq && LineReferentialSyncWorker
Refs #1707
-rw-r--r--Gemfile1
-rw-r--r--Gemfile.lock8
-rw-r--r--app/models/line_referential_sync.rb9
-rw-r--r--app/workers/line_referential_sync_worker.rb19
-rw-r--r--spec/workers/line_referential_sync_worker_spec.rb4
5 files changed, 36 insertions, 5 deletions
diff --git a/Gemfile b/Gemfile
index e2f6e1ca8..342e97ca8 100644
--- a/Gemfile
+++ b/Gemfile
@@ -103,6 +103,7 @@ gem 'acts_as_tree', '~> 2.1.0', require: 'acts_as_tree'
gem 'rabl'
+gem 'sidekiq'
gem 'delayed_job_active_record'
gem 'whenever', github: 'af83/whenever', require: false # '~> 0.9'
gem 'rake'
diff --git a/Gemfile.lock b/Gemfile.lock
index 39770f32b..08efe99f3 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -110,6 +110,8 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.9.1)
+ concurrent-ruby (1.0.2)
+ connection_pool (2.2.0)
crack (0.4.3)
safe_yaml (~> 1.0.0)
cucumber (2.4.0)
@@ -391,6 +393,7 @@ GEM
ffi (>= 0.5.0)
rdoc (4.2.0)
json (~> 1.4)
+ redis (3.3.1)
ref (2.0.0)
responders (1.1.2)
railties (>= 3.2, < 4.2)
@@ -443,6 +446,10 @@ GEM
shellany (0.0.1)
shoulda-matchers (2.8.0)
activesupport (>= 3.0.0)
+ sidekiq (4.1.0)
+ concurrent-ruby (~> 1.0)
+ connection_pool (~> 2.2, >= 2.2.0)
+ redis (~> 3.2, >= 3.2.1)
simple_form (3.1.0)
actionpack (~> 4.0)
activemodel (~> 4.0)
@@ -620,6 +627,7 @@ DEPENDENCIES
sawyer (~> 0.6.0)
sdoc (~> 0.4.0)
shoulda-matchers
+ sidekiq
simple_form (~> 3.1.0)
simplecov
simplecov-rcov
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
diff --git a/spec/workers/line_referential_sync_worker_spec.rb b/spec/workers/line_referential_sync_worker_spec.rb
new file mode 100644
index 000000000..0a1172e41
--- /dev/null
+++ b/spec/workers/line_referential_sync_worker_spec.rb
@@ -0,0 +1,4 @@
+require 'rails_helper'
+RSpec.describe LineReferentialSyncWorker, type: :worker do
+ pending "add some examples to (or delete) #{__FILE__}"
+end