backburner-allq 1.0.17 → 1.0.22

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: 2a73b5d7a8f60e385a3f600bfded5c0579691bbafdd4bc15b0f51e0df7298f4f
4
- data.tar.gz: 26000c93ce60b0f53ff666f51f7fcd1549ddde403dd400f7f4c457e056803c92
3
+ metadata.gz: '069b0228e7eee5979af0afe8d31601cd34400bb932009e86ffdef82e0d460dad'
4
+ data.tar.gz: 7aa635443fd85b5080dfe3ddf580cb8140d6c02855d7ee8642facf6b9b72300e
5
5
  SHA512:
6
- metadata.gz: a0d2079019d65e529e6b769ec860456bd13b2a29caf6797adcea9c1feca0f3b397d006ac9cd3e8a85e9d78a86af4ef8964d500d5822b001f730123705d80ada3
7
- data.tar.gz: 747c8436582124a553424a1e674ae97a44fee865f74720fbe5e84ca5fc6006a05087a7e1c079a6acdb72c2414c7b94db0642fefbba886734d8b575735411ecbb
6
+ metadata.gz: 6ad58a808c08fa4a75bf6911923fd82bb8d404cfa7f25ebcfffabddc07176fa1cf6089e0e648e6a99908b0b71fc5cf228e03f82dbdbca0d4820e11eb0d3cc90d
7
+ data.tar.gz: 3364c59a0d72be8a435a3e65e54a6b997c1576003155edc370d20e3a6dd1d7439420ca389d643b7d0d12c8806bc4bdced1f82c39b45e5b07168b50ad981241c6
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in backburner.gemspec
4
- gemspec
4
+ gemspec
5
+
6
+
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.17.gem
3
+ gem push backburner-allq-1.0.22.gem
@@ -81,6 +81,7 @@ module Backburner
81
81
  end
82
82
 
83
83
  class AllQWrapper
84
+ DEFAULT_TIMEOUT = 17800
84
85
  def initialize(url = 'localhost:8090')
85
86
  allq_conf = Allq::Configuration.new do |config|
86
87
  config.host = url
@@ -182,7 +183,7 @@ module Backburner
182
183
  def build_new_job(body, options)
183
184
  adjusted_priority = map_priority(options[:pri] || 5)
184
185
 
185
- ttl = options[:ttl] || 600
186
+ ttl = options[:ttl] || options[:ttr] || DEFAULT_TIMEOUT
186
187
  tube_name = options[:tube_name] || 'default'
187
188
  delay = options[:delay] || 0
188
189
  parent_id = options[:parent_id]
@@ -199,7 +200,7 @@ module Backburner
199
200
 
200
201
  def build_new_parent_job(body, options)
201
202
  adjusted_priority = map_priority(options[:pri] || 5)
202
- ttl = options[:ttl] || 600
203
+ ttl = options[:ttl] || options[:ttr] || DEFAULT_TIMEOUT
203
204
  tube_name = options[:tube_name] || 'default'
204
205
  delay = options[:delay] || 0
205
206
  parent_id = options[:parent_id]
@@ -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)
@@ -25,9 +25,10 @@ module Backburner
25
25
  @body = task.body.is_a?(Hash) ? task.body : Backburner.configuration.job_parser_proc.call(task.body)
26
26
  @name = body["class"] || body[:class]
27
27
  @args = body["args"] || body[:args]
28
+ @ttr = body["ttr"] || body[:ttr]
28
29
  rescue => ex # Job was not valid format
29
- self.bury
30
- raise JobFormatInvalid, "Job body could not be parsed: #{ex.inspect}"
30
+ # self.bury
31
+ # raise JobFormatInvalid, "Job body could not be parsed: #{ex.inspect}"
31
32
  end
32
33
 
33
34
  # Sets the delegator object to the underlying beaneater job
@@ -42,13 +43,13 @@ module Backburner
42
43
  # @example
43
44
  # @task.process
44
45
  #
45
- def process
46
+ def process
46
47
  # Invoke before hook and stop if false
47
48
  res = @hooks.invoke_hook_events(job_name, :before_perform, *args)
48
49
  return false unless res
49
50
  # Execute the job
50
51
  @hooks.around_hook_events(job_name, :around_perform, *args) do
51
- job_class.perform(*args)
52
+ timeout_job_after(@ttr > 1 ? @ttr - 1 : @ttr) { job_class.perform(*args) }
52
53
  end
53
54
  task.delete
54
55
  # Invoke after perform hook
@@ -60,12 +61,12 @@ module Backburner
60
61
 
61
62
  def bury
62
63
  @hooks.invoke_hook_events(job_name, :on_bury, *args)
63
- task.bury
64
+ @task.bury
64
65
  end
65
66
 
66
67
  def retry(count, delay)
67
68
  @hooks.invoke_hook_events(job_name, :on_retry, count, delay, *args)
68
- task.release(delay: delay)
69
+ @task.release(delay: delay)
69
70
  end
70
71
 
71
72
  # Returns the class for the job handler
@@ -1,3 +1,3 @@
1
1
  module Backburner
2
- VERSION = "1.0.17"
2
+ VERSION = "1.0.22"
3
3
  end
@@ -31,7 +31,7 @@ module Backburner
31
31
 
32
32
  return nil unless res # stop if hook is false
33
33
 
34
- data = { :class => job_class.name, :args => args }
34
+ data = { :class => job_class.name, :args => args, :ttr => ttr }
35
35
  queue = opts[:queue] && (Proc === opts[:queue] ? opts[:queue].call(job_class) : opts[:queue])
36
36
 
37
37
  begin
@@ -126,44 +126,53 @@ 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
- if job
138
- self.log_job_begin(job.name, job.args)
139
- job.process
140
- self.log_job_end(job.name)
141
-
142
- rescue Backburner::Job::JobFormatInvalid => e
143
- self.log_error self.exception_message(e)
144
- rescue => e # Error occurred processing job
145
- self.log_error self.exception_message(e) unless e.is_a?(Backburner::Job::RetryJob)
146
-
147
- unless job
148
- self.log_error "Error occurred before we were able to assign a job. Giving up without retrying!"
149
- return
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)
150
175
  end
151
-
152
- # NB: There's a slight chance here that the connection to allq has
153
- # gone down between the time we reserved / processed the job and here.
154
- num_retries = job.releases
155
- max_job_retries = resolve_max_job_retries(job.job_class)
156
- retry_status = "failed: attempt #{num_retries+1} of #{max_job_retries+1}"
157
- retry_delay = resolve_retry_delay(job.job_class)
158
- delay = resolve_retry_delay_proc(job.job_class).call(retry_delay, num_retries) rescue retry_delay
159
- if num_retries + 1 > max_job_retries
160
- job.bury
161
- else
162
- job.release(delay)
163
- end
164
- self.log_job_end(job.name, "#{retry_status}, retrying in #{delay}s") if job_started_at
165
-
166
- handle_error(e, job.name, job.args, job)
167
176
  end
168
177
  job
169
178
  end
@@ -177,9 +186,9 @@ module Backburner
177
186
  end
178
187
 
179
188
  # Reserve a job from the watched queues
180
- def reserve_job(conn, reserve_timeout = Backburner.configuration.reserve_timeout)
181
- job = conn.get(@tube_names.sample)
182
- return nil if job.body == nil?
189
+ def reserve_job(conn, tube_name, reserve_timeout = Backburner.configuration.reserve_timeout)
190
+ job = conn.get(tube_name)
191
+ return nil if job.nil? || job.body == nil?
183
192
  Backburner::Job.new(job)
184
193
  end
185
194
 
@@ -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,16 +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
- ran_job = work_one_job(conn)
213
+ ran_job = work_one_job(conn, @watched_tube_name)
211
214
  # Wait a second if we didn't find a job
212
- sleep(rand() * 3) unless ran_job
215
+ unless ran_job
216
+ puts "sleeping"
217
+ sleep(rand() * 3)
218
+ end
213
219
  end
214
220
  end
215
221
 
216
222
  # Shortcut for watching a tube on our beanstalk connection
217
223
  def watch_tube(name, conn = connection)
224
+ @watched_tube_name = name
218
225
  # No op for allq
219
226
  end
220
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.17
4
+ version: 1.0.22
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-13 00:00:00.000000000 Z
11
+ date: 2021-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: allq_rest