coney_island 0.10.1 → 0.10.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 789d4484a6d12b8c9f16dca1f0c1c87930396a27
4
- data.tar.gz: ffb7a60d798e6df10e85a1f7880d741fa5edf23d
3
+ metadata.gz: 8ace26e15f62cea555f90b2d01df1c171a663bdd
4
+ data.tar.gz: ac72a73cc54eef7b8ce0cf787bfd7cad67f7662c
5
5
  SHA512:
6
- metadata.gz: 19efec101621324b22d48430e64fde74e0de32119e364b63780ab20c3618b68bdebb5dc24c9f6c17051f9f7c017a0c7f789e14af8c750b41a5e82ac8d81846aa
7
- data.tar.gz: cf322ce204cf76588a5f827fec599c752f4e6d4b7c9d89391bc3d84f4b0d37201efcd05070924d0af21905be6c386f5d6d12e1c8c385bbedb71459c332a1a4e6
6
+ metadata.gz: d62459ea99bf7d992555add7bd1659aac5fd2422b94d8ad6c0e20b5802481857e5708445bdfe29e0beb41335225429bdbb9c88fe6952bf2530ecd5cdf15b8370
7
+ data.tar.gz: d7148fc33a739223600f3ba69e886c5054d011863b59304713d3933b7d2cd38a50e9943159ec8ca031fc6eb397f12af54eb6efa7be85d07d3bede9c8f4044f9f
@@ -50,6 +50,7 @@ module ConeyIsland
50
50
  end
51
51
 
52
52
  def handle_job
53
+ ConeyIsland::Worker.running_jobs << self
53
54
  Timeout::timeout(timeout) do
54
55
  execute_job_method
55
56
  end
@@ -63,32 +64,67 @@ module ConeyIsland
63
64
  ConeyIsland.submit(self.klass, self.method_name, self.resubmit_args)
64
65
  end
65
66
  rescue Exception => e
67
+ log.error("Error executing #{self.class_name}##{self.method_name} #{self.id} for id #{self.instance_id} with args #{self.args}:")
68
+ log.error(e.message)
69
+ log.error(e.backtrace.join("\n"))
66
70
  if retry_on_exception && (self.attempts < self.retry_limit)
67
- self.attempts += 1
68
71
  ConeyIsland.poke_the_badger(e, {work_queue: self.ticket, job_payload: self.args, attempt_count: self.attempts})
72
+ log.error("Resubmitting #{self.id} after error on attempt ##{self.attempts}")
73
+ self.attempts += 1
69
74
  ConeyIsland.submit(self.klass, self.method_name, self.resubmit_args)
70
- log.error("Resubmitting after error on attempt ##{self.attempts}:")
71
75
  else
72
76
  ConeyIsland.poke_the_badger(e, {work_queue: self.ticket, job_payload: self.args})
73
- log.error("Bailing out after error on final attempt ##{self.attempts}:")
77
+ log.error("Bailing out on #{self.id} after error on final attempt ##{self.attempts}:")
74
78
  end
75
- log.error("Error executing #{self.class_name}##{self.method_name} #{self.id} for id #{self.instance_id} with args #{self.args}:")
76
- log.error(e.message)
77
- log.error(e.backtrace.join("\n"))
78
79
  ensure
79
80
  finalize_job
80
81
  end
81
82
 
83
+ def next_attempt_delay
84
+ if self.delaying?
85
+ time_delayed = (Time.now - self.delay_start).round
86
+ new_delay = self.delay - time_delayed
87
+ else
88
+ ConeyIsland.delay_seed**(self.attempts - 1)
89
+ end
90
+ end
91
+
82
92
  def resubmit_args
83
93
  args.select{|key,val| ['timeout','retry_on_exception','retry_limit','args','instance_id'].include? key}.merge(
84
- 'attempt_count' => self.attempts, 'work_queue' => self.ticket, 'delay' => ConeyIsland.delay_seed**(self.attempts - 1))
94
+ 'attempt_count' => self.attempts, 'work_queue' => self.ticket, 'delay' => self.next_attempt_delay)
85
95
  end
86
96
 
87
97
  def finalize_job
88
- metadata.ack unless ConeyIsland.running_inline?
98
+ metadata.ack if !self.acked? && !ConeyIsland.running_inline?
89
99
  log.info("finished job #{id}")
90
100
  ConeyIsland::Worker.running_jobs.delete self
91
101
  end
92
102
 
103
+ def delaying?
104
+ @delaying
105
+ end
106
+
107
+ def acked?
108
+ @acked
109
+ end
110
+
111
+ def activate_after_delay
112
+ @delaying = false
113
+ ConeyIsland::Worker.delayed_jobs.delete self
114
+ end
115
+
116
+ def delay_job
117
+ @delaying = true
118
+ ConeyIsland::Worker.delayed_jobs << self
119
+ unless ConeyIsland.running_inline?
120
+ @acked = true
121
+ metadata.ack
122
+ end
123
+ log.info("delaying job #{id} for #{self.delay} seconds")
124
+ end
125
+
126
+ def requeue_delay
127
+ ConeyIsland.submit(self.klass, self.method_name, self.resubmit_args)
128
+ end
93
129
  end
94
130
  end
@@ -1,3 +1,3 @@
1
1
  module ConeyIsland
2
- VERSION = "0.10.1"
2
+ VERSION = "0.10.2"
3
3
  end
@@ -25,6 +25,10 @@ module ConeyIsland
25
25
  @running_jobs = []
26
26
  end
27
27
 
28
+ def self.delayed_jobs
29
+ @delayed_jobs ||= []
30
+ end
31
+
28
32
  def self.ticket
29
33
  @ticket
30
34
  end
@@ -160,9 +164,11 @@ module ConeyIsland
160
164
  begin
161
165
  args = JSON.parse(payload)
162
166
  job = Job.new(metadata, args)
163
- self.running_jobs << job
164
167
  if job.delay.present?
168
+ self.delayed_jobs << job
169
+ job.delay_job
165
170
  EventMachine.add_timer(job.delay) do
171
+ job.activate_after_delay
166
172
  job.handle_job
167
173
  end
168
174
  else
@@ -198,6 +204,9 @@ module ConeyIsland
198
204
  Process.kill(signal, child_pid)
199
205
  end
200
206
  @queue.unsubscribe rescue nil
207
+ self.delayed_jobs.each do |delayed_job|
208
+ delayed_job.requeue_delay
209
+ end
201
210
  EventMachine.add_periodic_timer(1) do
202
211
  if self.running_jobs.any?
203
212
  self.log.info("Waiting for #{self.running_jobs.length} requests to finish")
@@ -1,22 +1,12 @@
1
1
  ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
2
2
  Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
3
- Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
4
- ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
5
- Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
6
- ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
7
- Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
8
3
  ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
9
4
  Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
10
5
  ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
11
6
  Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
12
7
  ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
13
8
  Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
14
- ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
15
9
  Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
16
10
  ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
17
11
  Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
18
12
  ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
19
- ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
20
- Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
21
- ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
22
- Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
data/test/job_test.rb CHANGED
@@ -45,6 +45,7 @@ class JobTest < MiniTest::Test
45
45
  end
46
46
 
47
47
  it "bails out on timeout if retry limit reached" do
48
+ ConeyIsland.stop_running_inline
48
49
  job = ConeyIsland::Job.new(@metadata,
49
50
  { 'klass' => 'TestModel',
50
51
  'method_name' => :take_too_long,
@@ -79,6 +80,7 @@ class JobTest < MiniTest::Test
79
80
  end
80
81
 
81
82
  it "bails out on exception if retry_on_exception set and retry_limit reached" do
83
+ ConeyIsland.stop_running_inline
82
84
  job = ConeyIsland::Job.new(@metadata,
83
85
  { 'klass' => 'TestModel',
84
86
  'method_name' => :throw_an_error,
@@ -96,6 +98,7 @@ class JobTest < MiniTest::Test
96
98
  end
97
99
 
98
100
  it "bails out on exception if retry_on_exception not set" do
101
+ ConeyIsland.stop_running_inline
99
102
  job = ConeyIsland::Job.new(@metadata,
100
103
  { 'klass' => 'TestModel',
101
104
  'method_name' => :throw_an_error }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coney_island
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.1
4
+ version: 0.10.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Draut
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-03-11 00:00:00.000000000 Z
13
+ date: 2015-03-12 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails