backburner-allq 1.0.14 → 1.0.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 27888373123e4db33adc4349646b3313ff962e98a18a3ff26918e7efd701fa92
4
- data.tar.gz: b71459c2a3d38a986c86b7a51a238ada776f451ceb9a242dc74b58a9ca873149
3
+ metadata.gz: ed4aae689c12e639f2f51a32aef5a59c80f0ab452f89fe2f29afb566474ba201
4
+ data.tar.gz: 62e79b474949889a1b992b7fa25a034a1c87a62d1d6db0ba5f8a01582e464071
5
5
  SHA512:
6
- metadata.gz: 064e65cfb8c739d502b833007fb6b1c9d2c6ffd433c20b8f5501200c44047d596fbbf7eb0a0b55def1503193d0bedb4793c003d814b2986b164562d20f1f7ad0
7
- data.tar.gz: a6d06ecca8a34f24e1ab7b667a3334220dbfbb65e7e0da4b4884e8b40e491261316484133ec1ee14b144607c3e8adbc42f2fdbe9e3fc3fba880c63e50ae13cdf
6
+ metadata.gz: 8f5e2bd1006d8d39e95f25b85b195ad7b8cefd5b77a16dd93ab095ef0ca080d90e04b63490e66d9247b47e9f97d2355e5b2fa9fe03b2c85dd413efa54d642a32
7
+ data.tar.gz: 26a7b05894906fc6d79f0e98b6bed0f67d5ea8c62b09c3b6b89acb89fb13811dc568353ce7432d89081ed79ff97f4f2da5c91ee5e20ba2131cddf10a875da7c0
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in backburner.gemspec
4
- gemspec
4
+ gemspec
data/deploy.sh CHANGED
@@ -1,3 +1,3 @@
1
1
  echo "Did you update the version?"
2
2
  gem build backburner-allq.gemspec
3
- gem push backburner-allq-1.0.14.gem
3
+ gem push backburner-allq-1.0.20.gem
@@ -13,14 +13,16 @@ module Backburner
13
13
 
14
14
  def watch
15
15
  Thread.new do
16
- ran = false
17
- job = @allq_wrapper.get(@tube_name)
18
- if job.body
19
- perform(job)
20
- ran = true
16
+ loop do
17
+ ran = false
18
+ job = @allq_wrapper.get(@tube_name)
19
+ if job.body
20
+ perform(job)
21
+ ran = true
22
+ end
23
+ # Wait if nothing returned
24
+ sleep(rand() * 3) unless ran
21
25
  end
22
- # Wait if nothing returned
23
- sleep(rand() * 3) unless ran
24
26
  end
25
27
  end
26
28
  end
@@ -22,12 +22,12 @@ module Backburner
22
22
 
23
23
  def initialize
24
24
  @allq_url = "allq://127.0.0.1:8091"
25
- @tube_namespace = "backallq"
25
+ @tube_namespace = "backburner"
26
26
  @namespace_separator = "."
27
27
  @default_priority = 5
28
28
  @respond_timeout = 120
29
29
  @on_error = nil
30
- @max_job_retries = 0
30
+ @max_job_retries = 1
31
31
  @retry_delay = 5
32
32
  @retry_delay_proc = lambda { |min_retry_delay, num_retries| min_retry_delay + (num_retries ** 3) }
33
33
  @default_queues = []
@@ -38,6 +38,10 @@ module Backburner
38
38
  end
39
39
  end
40
40
 
41
+ def tubes
42
+ @allq_wrapper.tube_names if @allq_wrapper
43
+ end
44
+
41
45
  # Attempt to reconnect to allq. Note: the connection will not be watching
42
46
  # or using the tubes it was before it was reconnected (as it's actually a
43
47
  # completely new connection)
@@ -26,8 +26,8 @@ module Backburner
26
26
  @name = body["class"] || body[:class]
27
27
  @args = body["args"] || body[:args]
28
28
  rescue => ex # Job was not valid format
29
- self.bury
30
- raise JobFormatInvalid, "Job body could not be parsed: #{ex.inspect}"
29
+ # self.bury
30
+ # raise JobFormatInvalid, "Job body could not be parsed: #{ex.inspect}"
31
31
  end
32
32
 
33
33
  # Sets the delegator object to the underlying beaneater job
@@ -60,12 +60,12 @@ module Backburner
60
60
 
61
61
  def bury
62
62
  @hooks.invoke_hook_events(job_name, :on_bury, *args)
63
- task.bury
63
+ @task.bury
64
64
  end
65
65
 
66
66
  def retry(count, delay)
67
67
  @hooks.invoke_hook_events(job_name, :on_retry, count, delay, *args)
68
- task.release(delay: delay)
68
+ @task.release(delay: delay)
69
69
  end
70
70
 
71
71
  # Returns the class for the job handler
@@ -1,3 +1,3 @@
1
1
  module Backburner
2
- VERSION = "1.0.14"
2
+ VERSION = "1.0.20"
3
3
  end
@@ -126,43 +126,57 @@ module Backburner
126
126
  # @example
127
127
  # @worker.work_one_job
128
128
  # @raise [Beaneater::NotConnected] If beanstalk fails to connect multiple times.
129
- def work_one_job(conn = connection)
129
+ def work_one_job(conn = connection, tube_name = nil)
130
+ if tube_name.nil?
131
+ self.log_error "Sampling tube, this is bad practice for Allq"
132
+ tube_name = @tube_names.sample
133
+ end
134
+
130
135
  begin
131
- job = reserve_job(conn)
136
+ job = reserve_job(conn, tube_name)
132
137
  rescue Exception => e
138
+ self.log_error "Sleeping"
139
+ self.log_error "Exception: #{e.full_message}"
133
140
  sleep(rand*3)
134
141
  return
135
142
  end
136
143
 
137
- self.log_job_begin(job.name, job.args)
138
- job.process
139
- self.log_job_end(job.name)
140
-
141
- rescue Backburner::Job::JobFormatInvalid => e
142
- self.log_error self.exception_message(e)
143
- rescue => e # Error occurred processing job
144
- self.log_error self.exception_message(e) unless e.is_a?(Backburner::Job::RetryJob)
145
-
146
- unless job
147
- self.log_error "Error occurred before we were able to assign a job. Giving up without retrying!"
148
- return
149
- end
150
-
151
- # NB: There's a slight chance here that the connection to allq has
152
- # gone down between the time we reserved / processed the job and here.
153
- num_retries = job.releases
154
- max_job_retries = resolve_max_job_retries(job.job_class)
155
- retry_status = "failed: attempt #{num_retries+1} of #{max_job_retries+1}"
156
- retry_delay = resolve_retry_delay(job.job_class)
157
- delay = resolve_retry_delay_proc(job.job_class).call(retry_delay, num_retries) rescue retry_delay
158
- if num_retries + 1 > max_job_retries
159
- job.bury
144
+ if job && job.body
145
+ begin
146
+ self.log_job_begin(job.name, job.args)
147
+ job.process
148
+ self.log_job_end(job.name)
149
+ rescue Backburner::Job::JobFormatInvalid => e
150
+ self.log_error self.exception_message(e)
151
+ rescue => e # Error occurred processing job
152
+ self.log_error self.exception_message(e) unless e.is_a?(Backburner::Job::RetryJob)
153
+
154
+ unless job
155
+ self.log_error "Error occurred before we were able to assign a job. Giving up without retrying!"
156
+ return
157
+ end
158
+
159
+ # NB: There's a slight chance here that the connection to allq has
160
+ # gone down between the time we reserved / processed the job and here.
161
+ num_retries = job.releases
162
+ max_job_retries = resolve_max_job_retries(job.job_class)
163
+ retry_status = "failed: attempt #{num_retries+1} of #{max_job_retries+1}"
164
+ retry_delay = resolve_retry_delay(job.job_class)
165
+ delay = resolve_retry_delay_proc(job.job_class).call(retry_delay, num_retries) rescue retry_delay
166
+
167
+ if num_retries + 1 > max_job_retries
168
+ job.bury
169
+ else
170
+ job.release(delay)
171
+ end
172
+ self.log_job_end(job.name, "#{retry_status}, retrying in #{delay}s") if job_started_at
173
+
174
+ handle_error(e, job.name, job.args, job)
175
+ end
160
176
  else
161
- job.release(delay)
177
+ sleep(rand*3)
162
178
  end
163
- self.log_job_end(job.name, "#{retry_status}, retrying in #{delay}s") if job_started_at
164
-
165
- handle_error(e, job.name, job.args, job)
179
+ job
166
180
  end
167
181
 
168
182
 
@@ -174,8 +188,10 @@ module Backburner
174
188
  end
175
189
 
176
190
  # Reserve a job from the watched queues
177
- def reserve_job(conn, reserve_timeout = Backburner.configuration.reserve_timeout)
178
- Backburner::Job.new(conn.get(@tube_names.sample))
191
+ def reserve_job(conn, tube_name, reserve_timeout = Backburner.configuration.reserve_timeout)
192
+ job = conn.get(tube_name)
193
+ return nil if job.nil? || job.body == nil?
194
+ Backburner::Job.new(job)
179
195
  end
180
196
 
181
197
  # Returns a list of all tubes known within the system
@@ -11,7 +11,7 @@ module Backburner
11
11
  def prepare
12
12
  self.tube_names.map! { |name| expand_tube_name(name) }.uniq!
13
13
  log_info "Working #{tube_names.size} queues: [ #{tube_names.join(', ')} ]"
14
- self.connection.tubes.watch!(*self.tube_names)
14
+ # self.connection.tubes.watch!(*self.tube_names)
15
15
  end
16
16
 
17
17
  # Starts processing new jobs indefinitely.
@@ -11,7 +11,7 @@ module Backburner
11
11
  def prepare
12
12
  self.tube_names.map! { |name| expand_tube_name(name) }.uniq!
13
13
  log_info "Working #{tube_names.size} queues: [ #{tube_names.join(', ')} ]"
14
- self.connection.tubes.watch!(*self.tube_names)
14
+ # self.connection.tubes.watch!(*self.tube_names)
15
15
  end
16
16
 
17
17
  # Starts processing new jobs indefinitely.
@@ -49,8 +49,8 @@ module Backburner
49
49
  @thread_pools.each do |tube_name, pool|
50
50
  pool.max_length.times do
51
51
  # Create a new connection and set it up to listen on this tube name
52
- connection = new_connection.tap{ |conn| conn.tubes.watch!(tube_name) }
53
- connection.on_reconnect = lambda { |conn| conn.tubes.watch!(tube_name) }
52
+ # connection = new_connection.tap{ |conn| conn.tubes.watch!(tube_name) }
53
+ # connection.on_reconnect = lambda { |conn| conn.tubes.watch!(tube_name) }
54
54
 
55
55
  # Make it work jobs using its own connection per thread
56
56
  pool.post(connection) do |memo_connection|
@@ -58,7 +58,7 @@ module Backburner
58
58
  loop do
59
59
  begin
60
60
  break if @in_shutdown
61
- work_one_job(memo_connection)
61
+ work_one_job(memo_connection, tube_name)
62
62
  rescue => e
63
63
  log_error("Exception caught in thread pool loop. Continuing. -> #{e.message}\nBacktrace: #{e.backtrace}")
64
64
  end
@@ -181,6 +181,8 @@ module Backburner
181
181
 
182
182
  @runs = 0
183
183
 
184
+ puts "Threads number = #{@threads_number}"
185
+
184
186
  if @threads_number == 1
185
187
  watch_tube(name)
186
188
  run_while_can
@@ -205,14 +207,21 @@ module Backburner
205
207
 
206
208
  # Run work_one_job while we can
207
209
  def run_while_can(conn = connection)
210
+ puts "Run while can"
208
211
  while @garbage_after.nil? or @garbage_after > @runs
209
212
  @runs += 1 # FIXME: Likely race condition
210
- work_one_job(conn)
213
+ ran_job = work_one_job(conn, @watched_tube_name)
214
+ # Wait a second if we didn't find a job
215
+ unless ran_job
216
+ puts "sleeping"
217
+ sleep(rand() * 3)
218
+ end
211
219
  end
212
220
  end
213
221
 
214
222
  # Shortcut for watching a tube on our beanstalk connection
215
223
  def watch_tube(name, conn = connection)
224
+ @watched_tube_name = name
216
225
  # No op for allq
217
226
  end
218
227
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: backburner-allq
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.14
4
+ version: 1.0.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Malcolm
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-02 00:00:00.000000000 Z
11
+ date: 2021-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: allq_rest