backburner-allq 1.0.5 → 1.0.12

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
  SHA256:
3
- metadata.gz: c571fab5da811c77fe0bf58bed5f808fa8981b9730bee955cb82ae3e90695c1d
4
- data.tar.gz: c365ca785e4a5d5ed0db33654d2d2d8dc9941a1b251bae20b1c445c1703dd565
3
+ metadata.gz: 7876b8c587bb8dcd70760ec2f29395d5c37cb14c0e4980217a9a8b4e6c4163a5
4
+ data.tar.gz: 40fbe69e88ab561358a19035ae102e345635891fc7bd9ff1c24b9d0beb033e4e
5
5
  SHA512:
6
- metadata.gz: a66719f1557c17349478db2a21d2ee72e136582fa0329afc8c52d29187b96817a0608d0bbde79ef3f6e7feb5d0fb370bf55d470faa7be7b49e3e7f4bd5d9a77f
7
- data.tar.gz: e952ae3e8eb9427055b7dfc6612a4fda9d79bdc767a2af0da2ea7559be93bf35f1972bf23d95c209a810e90fc8c95977b95d8f4213691aed27408f26409218c1
6
+ metadata.gz: 345458382a5f37e53b816d3ede71ae75ec3abf82fff70c5a2607184992303ee00b3f2351bfa8ff4b770191369aaddb7b82aeb9255cfc92d3f0c893f21ac4bb54
7
+ data.tar.gz: 7fb582110bc654bf7645584e70c01a3c681c4c4137db190dead765c73146882931251f9292a291b2faab8976383e595b062df22bf1bacc88ddf3940575dd7671
@@ -1,133 +1,4 @@
1
1
  # CHANGELOG
2
2
 
3
- ## Version 1.5.0 (September 10 2018)
4
-
5
- * TBD
6
-
7
- ## Version 1.4.1 (June 10 2017)
8
-
9
- * Fix warning for constant ::Fixnum is deprecated (@amatsuda)
10
-
11
- ## Version 1.4.0 (May 13 2017)
12
-
13
- * Fix unit tests to be more consistent (@eltone)
14
- * Ensure job supports body hash with symbol keys (@eltone)
15
- * Add support for custom serialization formats (@eltone)
16
- * Log the params when a job timeout occurs (@nathantsoi)
17
-
18
- ## Version 1.3.1 (April 21 2016)
19
-
20
- * Addition of thread-pool-based concurrency (@contentfree)
21
-
22
- ## Version 1.3.0 (February 05 2016)
23
-
24
- * Enqueue command now responds with beanstalk response details
25
-
26
- ## Version 1.2.0 (November 01 2015)
27
-
28
- * FIX Made connections to beanstalkd more resilient (@contentfree)
29
-
30
- ## Version 1.2.0.pre (October 24 2015)
31
-
32
- * FIX Replace static Beaneater connection with individual connections per worker instance/thread (@contentfree)
33
- * FIX Beaneater connections try really hard to repair themselves if disconnected accidentally (@contentfree)
34
- * NEW Event hook for workers: on_reconnect (@contentfree)
35
-
36
- ## Version 1.1.0 (September 14 2015)
37
-
38
- * NEW Ability to configure namespace separator (@bfolkens)
39
- * NEW Avoid timeouts altogether by setting queue_respond_timeout to 0 (@zacviandier)
40
- * NEW Event hooks for on_retry and on_bury (@contentfree)
41
- * NEW Support lambdas for queue names (@contentfree)
42
- * NEW Allow for control of delay calculation (@contentfree)
43
- * NEW Ability to specify environment when running the CLI (@contentfree)
44
- * NEW Control default async behavior of methods (@contentfree)
45
-
46
- ## Version 1.0.0 (April 26 2015)
47
-
48
- * NEW Updating to Beaneater 1.0 (@alup)
49
-
50
- ## Version 0.4.6 (October 26 2014)
51
-
52
- * NEW Add job to on_error handler if the handler has a 4th argument (@Nitrodist)
53
- * NEW Use a timeout when looking for a job to reserve (@EasyPost)
54
- * NEW Support configuring settings on threads on fork class (@silentshade)
55
- * FIX queue override by existing queues (@silentshade)
56
- * FIX Use thread to log exit message (@silentshade)
57
-
58
- ## Version 0.4.5 (December 16 2013)
59
-
60
- * FIX #47 Create a backburner connection per thread (Thanks @thcrock)
61
-
62
- ## Version 0.4.4 (October 27 2013)
63
-
64
- * NEW #51 Added ability to set per-queue default ttr's (Thanks @ryanjohns)
65
-
66
- ## Version 0.4.3 (July 19 2013)
67
-
68
- * FIX #44 Additional fix to issue introduced in 0.4.2
69
- * FIX #45 More graceful shutdown using Kernel.exit and rescuing SystemExit. (Thanks @ryanjohns)
70
-
71
- ## Version 0.4.2 (July 3 2013)
72
-
73
- * FIX #44 Properly retry to connect to beanstalkd when connection fails.
74
-
75
- ## Version 0.4.1 (June 28 2013)
76
-
77
- * FIX #43 Properly support CLI options and smart load the app environment.
78
-
79
- ## Version 0.4.0 (June 28 2013)
80
-
81
- NOTE: This is the start of working with @bradgessler to improve backburner and merge with quebert
82
-
83
- * NEW #26 #27 Remove need for Queue mixin, allow plain ruby objects
84
- * NEW Default all jobs to a single general queue rather than separate queues
85
- * NEW Add support for named priorities, allowing shorthand names for priority values
86
-
87
- ## Version 0.3.4 (April 23 2013)
88
-
89
- * FIX #22 Adds signal handlers for worker to manage proper shutdown (Thanks @tkiley)
90
-
91
- ## Version 0.3.3 (April 19 2013)
92
-
93
- * Fix naming conflict rename 'config' to 'queue_config'
94
-
95
- ## Version 0.3.2 (Jan 23 2013)
96
-
97
- * Bump version of beaneater to 0.3.0 (better socket handling)
98
-
99
- ## Version 0.3.1 (Dec 28 2012)
100
-
101
- * Adds basic forking processing strategy and rake tasks (Thanks @danielfarrell)
102
-
103
- ## Version 0.3.0 (Nov 14 2012)
104
-
105
- * Major update with support for a 'threads_on_fork' processing strategy (Thanks @ShadowBelmolve)
106
- * Different workers have different rake tasks (Thanks @ShadowBelmolve)
107
- * Added processing strategy specific examples i.e stress.rb and adds new unit tests. (Thanks @ShadowBelmolve)
108
-
109
- ## Version 0.2.6 (Nov 12 2012)
110
-
111
- * Upgrade to beaneater 0.2.0
112
-
113
- ## Version 0.2.5 (Nov 9 2012)
114
-
115
- * Add support for multiple worker processing strategies through subclassing.
116
-
117
- ## Version 0.2.0 (Nov 7 2012)
118
-
119
- * Add new plugin hooks feature (see HOOKS.md)
120
-
121
- ## Version 0.1.2 (Nov 7 2012)
122
-
123
- * Adds ability to specify a custom logger.
124
- * Adds job retry configuration and worker support.
125
-
126
- ## Version 0.1.1 (Nov 6 2012)
127
-
128
- * Fix issue with timed out reserves
129
-
130
- ## Version 0.1.0 (Nov 4 2012)
131
-
132
- * Switch to beaneater as new ruby beanstalkd client
133
- * Add support for array of connections in `beanstalk_url`
3
+ ## Version 1.0.9 (September 9 2020)
4
+ Branched from backburner to use Allq instead
data/HOOKS.md CHANGED
@@ -6,7 +6,7 @@ In many cases you can use a hook rather than mess around with Backburner's inter
6
6
  ## Job Hooks
7
7
 
8
8
  Hooks are transparently adapted from [Resque](https://github.com/resque/resque/blob/master/docs/HOOKS.md), so
9
- if you are familiar with their hook API, now you can use nearly the same ones with beanstalkd and backburner!
9
+ if you are familiar with their hook API, now you can use nearly the same ones with allq and backburner!
10
10
 
11
11
  There are a variety of hooks available that are triggered during the lifecycle of a job:
12
12
 
data/README.md CHANGED
@@ -1,14 +1,14 @@
1
1
  # Backburner [![Build Status](https://travis-ci.org/nesquena/backburner.svg?branch=master)](https://travis-ci.org/nesquena/backburner)
2
2
 
3
- Backburner is a [beanstalkd](http://kr.github.com/beanstalkd/)-powered job queue that can handle a very high volume of jobs.
3
+ Backburner-allq is a [allq](http://www.allqueue.com)-powered job queue that can handle a very high volume of jobs.
4
4
  You create background jobs and place them on multiple work queues to be processed later.
5
5
 
6
- Processing background jobs reliably has never been easier than with beanstalkd and Backburner. This gem works with any ruby-based
6
+ Processing background jobs reliably has never been easier than with allq and Backburner. This gem works with any ruby-based
7
7
  web framework, but is especially suited for use with [Sinatra](http://sinatrarb.com), [Padrino](http://padrinorb.com) and Rails.
8
8
 
9
- If you want to use beanstalk for your job processing, consider using Backburner.
9
+ If you want to use allq for your job processing, consider using Backburner.
10
10
  Backburner is heavily inspired by Resque and DelayedJob. Backburner stores all jobs as simple JSON message payloads.
11
- Persistent queues are supported when beanstalkd persistence mode is enabled.
11
+ Persistent queues are supported when allq persistence mode is enabled.
12
12
 
13
13
  Backburner supports multiple queues, job priorities, delays, and timeouts. In addition,
14
14
  Backburner has robust support for retrying failed jobs, handling error cases,
@@ -26,28 +26,14 @@ libraries under the hood. Every job queue requires a queue store that jobs are p
26
26
  In the case of Resque, jobs are processed through **Redis**, a persistent key-value store. In the case of DelayedJob, jobs are processed through
27
27
  **ActiveRecord** and a database such as PostgreSQL.
28
28
 
29
- The work queue underlying these gems tells you infinitely more about the differences than anything else.
30
- Beanstalk is probably the best solution for job queues available today for many reasons.
31
- The real question then is... "Why Beanstalk?".
32
29
 
33
- ## Why Beanstalk?
30
+ You will quickly see that **allq** is an underrated but incredible project that is extremely well-suited as a job queue.
31
+ Significantly better suited for this task than Redis or a database.
34
32
 
35
- Illya has an excellent blog post
36
- [Scalable Work Queues with Beanstalk](http://www.igvita.com/2010/05/20/scalable-work-queues-with-beanstalk/) and
37
- Adam Wiggins posted [an excellent comparison](http://adam.herokuapp.com/past/2010/4/24/beanstalk_a_simple_and_fast_queueing_backend/).
33
+ A single instance of Allq is perfectly capable of handling thousands of jobs a second (or more, depending on your job size)
34
+ because it is an in-memory, event-driven system.
38
35
 
39
- You will quickly see that **beanstalkd** is an underrated but incredible project that is extremely well-suited as a job queue.
40
- Significantly better suited for this task than Redis or a database. Beanstalk is a simple,
41
- and a very fast work queue service rolled into a single binary - it is the memcached of work queues.
42
- Originally built to power the backend for the 'Causes' Facebook app, it is a mature and production ready open source project.
43
- [PostRank](http://www.postrank.com) uses beanstalk to reliably process millions of jobs a day.
44
-
45
- A single instance of Beanstalk is perfectly capable of handling thousands of jobs a second (or more, depending on your job size)
46
- because it is an in-memory, event-driven system. Powered by libevent under the hood,
47
- it requires zero setup (launch and forget, à la memcached), optional log based persistence, an easily parsed ASCII protocol,
48
- and a rich set of tools for job management that go well beyond a simple FIFO work queue.
49
-
50
- Beanstalkd supports the following features out of the box:
36
+ Allq supports the following features out of the box:
51
37
 
52
38
  | Feature | Description |
53
39
  | ------- | ------------------------------- |
@@ -59,27 +45,14 @@ Beanstalkd supports the following features out of the box:
59
45
  | **Persistence** | Jobs are stored in memory for speed, but logged to disk for safe keeping. |
60
46
  | **Federation** | Horizontal scalability provided through federation by the client. |
61
47
  | **Error Handling** | Bury any job which causes an error for later debugging and inspection.|
48
+ | **Fair Queueing** | Allows you to shard work across queues for fair client queuing.|
49
+ | **Workflows** | Allows you tell Job C to wait for Job A and Job B to finish first.|
62
50
 
63
- Keep in mind that these features are supported out of the box with beanstalk and require no special code within this gem to support.
64
- In the end, **beanstalk is the ideal job queue** while also being ridiculously easy to install and setup.
51
+ Keep in mind that these features are supported out of the box with allq and require no special code within this gem to support.
52
+ In the end, **allq is the ideal job queue** while also being ridiculously easy to install and setup.
65
53
 
66
54
  ## Installation
67
55
 
68
- First, you probably want to [install beanstalkd](http://kr.github.com/beanstalkd/download.html), which powers the job queues.
69
- Depending on your platform, this should be as simple as (for Ubuntu):
70
-
71
- $ sudo apt-get install beanstalkd
72
-
73
- Add this line to your application's Gemfile:
74
-
75
- gem 'backburner'
76
-
77
- And then execute:
78
-
79
- $ bundle
80
-
81
- Or install it yourself as:
82
-
83
56
  $ gem install backburner
84
57
 
85
58
  ## Configuration ##
@@ -88,7 +61,7 @@ Backburner is extremely simple to setup. Just configure basic settings for backb
88
61
 
89
62
  ```ruby
90
63
  Backburner.configure do |config|
91
- config.beanstalk_url = "beanstalk://127.0.0.1"
64
+ config.beanstalk_url = "allq://127.0.0.1:8090"
92
65
  config.tube_namespace = "some.app.production"
93
66
  config.namespace_separator = "."
94
67
  config.on_error = lambda { |e| puts e }
@@ -112,7 +85,7 @@ The key options available are:
112
85
 
113
86
  | Option | Description |
114
87
  | ----------------- | ------------------------------- |
115
- | `beanstalk_url` | Address for beanstalkd connection i.e 'beanstalk://127.0.0.1' |
88
+ | `allq_url` | Address for allq connection i.e 'allq://127.0.0.1:8090' |
116
89
  | `tube_namespace` | Prefix used for all tubes related to this backburner queue. |
117
90
  | `namespace_separator` | Separator used for namespace and queue name |
118
91
  | `on_error` | Lambda invoked with the error whenever any job in the system fails. |
@@ -129,15 +102,10 @@ The key options available are:
129
102
  | `job_serializer_proc` | Lambda serializes a job body to a string to write to the task |
130
103
  | `job_parser_proc` | Lambda parses a task body string to a hash |
131
104
 
132
- ## Breaking Changes
133
-
134
- Before **v0.4.0**: Jobs were placed into default queues based on the name of the class creating the queue. i.e NewsletterJob would
135
- be put into a 'newsletter-job' queue. As of 0.4.0, all jobs are placed into a primary queue named "my.app.namespace.backburner-jobs"
136
- unless otherwise specified.
137
105
 
138
106
  ## Usage
139
107
 
140
- Backburner allows you to create jobs and place them onto any number of beanstalk tubes, and later pull those jobs off the tubes and
108
+ Backburner allows you to create jobs and place them onto any number of allq tubes, and later pull those jobs off the tubes and
141
109
  process them asynchronously with a worker.
142
110
 
143
111
  ### Enqueuing Jobs ###
@@ -165,7 +133,7 @@ class NewsletterJob
165
133
 
166
134
  # optional, defaults to respond_timeout in config
167
135
  def self.queue_respond_timeout
168
- 300 # number of seconds before job times out, 0 to avoid timeout. NB: A timeout of 1 second will likely lead to race conditions between Backburner and beanstalkd and should be avoided
136
+ 300 # number of seconds before job times out, 0 to avoid timeout. NB: A timeout of 1 second will likely lead to race conditions between Backburner and allq and should be avoided
169
137
  end
170
138
 
171
139
  # optional, defaults to retry_delay_proc in config
@@ -387,15 +355,15 @@ This is why our examples use object IDs instead of passing around objects.
387
355
 
388
356
  ### Named Priorities
389
357
 
390
- As of v0.4.0, Backburner has support for named priorities. beanstalkd priorities are numerical but
358
+ As of v0.4.0, Backburner has support for named priorities. allq priorities are numerical but
391
359
  backburner supports a mapping between a word and a numerical value. The following priorities are
392
- available by default: `high` is 0, `medium` is 100, and `low` is 200.
360
+ available by default: `high` is 0, `medium` is 4, and `low` is 9.
393
361
 
394
362
  Priorities can be customized with:
395
363
 
396
364
  ```ruby
397
365
  Backburner.configure do |config|
398
- config.priority_labels = { :custom => 50, :useful => 5 }
366
+ config.priority_labels = { :custom => 1, :useful => 5 }
399
367
  # or append to default priorities with
400
368
  # config.priority_labels = Backburner::Configuration::PRIORITY_LABELS.merge(:foo => 5)
401
369
  end
@@ -557,8 +525,7 @@ Check out [HOOKS.md](https://github.com/nesquena/backburner/blob/master/HOOKS.md
557
525
 
558
526
  ### Workers in Production
559
527
 
560
- Once you have Backburner setup in your application, starting workers is really easy. Once [beanstalkd](http://kr.github.com/beanstalkd/download.html)
561
- is installed, your best bet is to use the built-in rake task that comes with Backburner. Simply add the task to your Rakefile:
528
+ Once you have Backburner setup in your application, starting workers is really easy. Simply add the task to your Rakefile:
562
529
 
563
530
  ```ruby
564
531
  # Rakefile
@@ -609,8 +576,7 @@ backburner -e $environment
609
576
 
610
577
  #### Reconnecting
611
578
 
612
- In Backburner, if the beanstalkd connection is temporarily severed, several retries to establish the connection will be attempted.
613
- After several retries, if the connection is still not able to be made, a `Beaneater::NotConnected` exception will be raised.
579
+ In Backburner, if the allq connection is temporarily severed, several retries to establish the connection will be attempted.
614
580
  You can manually catch this exception, and attempt another manual retry using `Backburner::Worker.retry_connection!`.
615
581
 
616
582
  ### Web Front-end
data/TODO CHANGED
@@ -1,4 +0,0 @@
1
- - Custom front-end in sinatra for viewing beanstalk jobs
2
- - Refer to https://github.com/denniskuczynski/beanstalkd_view
3
- - Fork jobs to control memory
4
- - https://github.com/michaeldwan/stalker/commit/386267690a7c03e11d1a8b7b6f08b7c9c7cd2c0d
@@ -4,9 +4,9 @@ require File.expand_path('../lib/backburner/version', __FILE__)
4
4
  Gem::Specification.new do |s|
5
5
  s.authors = ["Jason Malcolm"]
6
6
  s.email = ["jason@blitline.com"]
7
- s.description = %q{Beanstalk background job processing made easy}
7
+ s.description = %q{Allq background job processing made easy}
8
8
  s.summary = %q{Reliable allq background job processing made easy for Ruby and Sinatra}
9
- s.homepage = "http://github.com/nesquena/backburner"
9
+ s.homepage = "http://github.com/blitline-dev/backburner-allq"
10
10
 
11
11
  s.files = `git ls-files`.split($\)
12
12
  s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
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.5.gem
3
+ gem push backburner-allq-1.0.12.gem
@@ -79,7 +79,7 @@ module Backburner
79
79
  end
80
80
 
81
81
  class AllQWrapper
82
- def initialize(url = Blitline::Constants::ALLQ_DEFAULT_EU_URL)
82
+ def initialize(url = 'localhost:8090')
83
83
  allq_conf = Allq::Configuration.new do |config|
84
84
  config.host = url
85
85
  end
@@ -114,7 +114,9 @@ module Backburner
114
114
  @client.release_put(job.id)
115
115
  end
116
116
 
117
- def bury(job); end
117
+ def bury(job)
118
+ @client.bury_put(job.id)
119
+ end
118
120
 
119
121
  def tube_names
120
122
  stats_hash = stats
@@ -127,35 +129,30 @@ module Backburner
127
129
  return nil if job.body.nil?
128
130
 
129
131
  job.body = Base64.decode64(job.body) if job
130
- job_obj = Blitline::AllQJob.new(self, job)
132
+ job_obj = Backburner::AllQJob.new(self, job)
131
133
  job_obj
132
134
  end
133
135
 
134
136
  def get(tube_name = 'default')
135
137
  job = nil
136
- delt = Blitline::Utils.get_delta do
137
- job = @client.job_get(tube_name)
138
- end
139
- puts "Allq http get delta: #{delt} #{tube_name} #{job}" if delt.to_f > 1.5
138
+ job = @client.job_get(tube_name)
140
139
 
141
- @recent_times.push(delt.to_f)
142
- @recent_times.shift if @recent_times.size > 2
143
140
  # Inplace decode
144
141
  job.body = Base64.decode64(job.body) if job&.body
145
142
 
146
- job_obj = Blitline::AllQJob.new(self, job)
143
+ job_obj = Backburner::AllQJob.new(self, job)
147
144
  job_obj
148
145
  rescue StandardError => ex
149
146
  if ex.message == "Couldn't resolve host name"
150
- BlitlineLogger.log("COUDNT RESOLVE HOST NAME------ SHOULD REBOOT")
147
+ puts("COUDNT RESOLVE HOST NAME------ SHOULD REBOOT")
151
148
  else
152
- BlitlineLogger.log(ex)
149
+ puts(ex)
153
150
  end
154
151
  end
155
152
 
156
153
  def close
157
154
  rescue StandardError => ex
158
- BlitlineLogger.log(ex)
155
+ puts(ex)
159
156
  end
160
157
 
161
158
  def map_priority(app_priority)
@@ -166,21 +163,14 @@ module Backburner
166
163
 
167
164
  default = 5
168
165
 
169
- return default if app_priority == 32_000
170
-
171
- return 6 if app_priority >= 33_000
172
-
173
- return 7 if app_priority >= 35_000
174
-
175
- return 8 if app_priority >= 37_000
176
-
177
- default
166
+ # return app_priority unless larger than 10
167
+ app_priority > 10 ? 5 : app_priority
178
168
  end
179
169
 
180
170
  def log_result(job_result)
181
- BlitlineLogger.log("ALLQ-HTTP-JOB-ID=#{job_result.job_id}")
171
+ puts("ALLQ-HTTP-JOB-ID=#{job_result.job_id}")
182
172
  rescue StandardError => ex
183
- BlitlineLogger.log(ex)
173
+ puts(ex)
184
174
  end
185
175
 
186
176
  def build_new_job(body, options)
@@ -196,6 +186,7 @@ module Backburner
196
186
  ttl: ttl,
197
187
  delay: delay,
198
188
  priority: adjusted_priority,
189
+ shard_key: options[:shard_key],
199
190
  parent_id: parent_id)
200
191
  new_job
201
192
  end
@@ -217,21 +208,11 @@ module Backburner
217
208
  priority: adjusted_priority,
218
209
  timeout: timeout,
219
210
  run_on_timeout: run_on_timeout,
211
+ shard_key: options[:shard_key]
220
212
  limit: limit)
221
213
  new_parent_job
222
214
  end
223
215
 
224
- def put2(body, pri = 5, ttl = 600, tube_name = "default", delay = 0)
225
- # Old school way
226
- options = {
227
- pri: pri,
228
- ttl: ttl,
229
- tube_name: tube_name,
230
- delay: delay
231
- }
232
- put(body, options)
233
- end
234
-
235
216
  def put(body, options)
236
217
  # New school put
237
218
  retry_count = 0
@@ -241,30 +222,26 @@ module Backburner
241
222
  begin
242
223
  Timeout.timeout(10) do
243
224
  if body && body.to_s.include?('["default"]')
244
- BlitlineLogger.log "PUTTING DEFAULT! #{caller.inspect}"
245
225
  end
246
226
 
247
- delt = Blitline::Utils.get_delta do
248
- if is_parent
249
- new_job = build_new_parent_job(body, options)
250
- result = @client.parent_job_post(new_job)
251
- else
252
- new_job = build_new_job(body, options)
253
- result = @client.job_post(new_job)
254
- end
255
- raise 'PUT returned nil' if result.nil? || result.to_s == ''
227
+ if is_parent
228
+ new_job = build_new_parent_job(body, options)
229
+ result = @client.parent_job_post(new_job)
230
+ else
231
+ new_job = build_new_job(body, options)
232
+ result = @client.job_post(new_job)
256
233
  end
257
- BlitlineLogger.log "Allq http put delta: #{delt}"
234
+ raise 'PUT returned nil' if result.nil? || result.to_s == ''
258
235
  end
259
236
  rescue Timeout::Error
260
- BlitlineLogger.log('ALLQ_PUT_TIMEOUT')
237
+ puts('ALLQ_PUT_TIMEOUT')
261
238
  sleep(5)
262
239
  retry_count += 1
263
240
  retry if retry_count < 4
264
241
  raise 'Failed to put on allq, we are investigating the problem, please try again'
265
242
  rescue StandardError => ex
266
- BlitlineLogger.log('Failed to ALLQ PUT')
267
- BlitlineLogger.log(ex)
243
+ puts('Failed to ALLQ PUT')
244
+ puts(ex)
268
245
  retry_count += 1
269
246
  sleep(5)
270
247
  retry if retry_count < 4
@@ -290,7 +267,7 @@ module Backburner
290
267
  end
291
268
  final_stats
292
269
  rescue StandardError => ex
293
- BlitlineLogger.log(ex)
270
+ puts(ex)
294
271
  {}
295
272
  end
296
273
 
@@ -300,7 +277,7 @@ module Backburner
300
277
  count = tube_stats['ready'].to_i if tube_stats && tube_stats['ready']
301
278
  count
302
279
  rescue StandardError => ex
303
- BlitlineLogger.log(ex)
280
+ puts(ex)
304
281
  -1
305
282
  end
306
283
 
@@ -308,7 +285,7 @@ module Backburner
308
285
  result = get_ready_by_tube('default')
309
286
  result.to_i
310
287
  rescue StandardError => ex
311
- BlitlineLogger.log(ex)
288
+ puts(ex)
312
289
  0
313
290
  end
314
291
  end
@@ -21,8 +21,8 @@ module Backburner
21
21
  attr_accessor :job_parser_proc # proc to parse a job body from a string
22
22
 
23
23
  def initialize
24
- @allq_url = "127.0.0.1:8090"
25
- @tube_namespace = ""
24
+ @allq_url = "allq://127.0.0.1:8091"
25
+ @tube_namespace = "backallq"
26
26
  @namespace_separator = "."
27
27
  @default_priority = 5
28
28
  @respond_timeout = 120
@@ -1,7 +1,7 @@
1
1
  require 'delegate'
2
2
 
3
3
  module Backburner
4
- class Connection < SimpleDelegator
4
+ class Connection
5
5
  class BadURL < RuntimeError; end
6
6
 
7
7
  attr_accessor :url, :allq_wrapper
@@ -27,7 +27,6 @@ module Backburner
27
27
  def close
28
28
  @allq_wrapper.close if @allq_wrapper
29
29
  @allq_wrapper = nil
30
- __setobj__(@allq_wrapper)
31
30
  end
32
31
 
33
32
  # Determines if the connection to allq is currently open
@@ -67,7 +66,7 @@ module Backburner
67
66
  begin
68
67
  yield
69
68
 
70
- rescue Beaneater::NotConnected
69
+ rescue Exception => e
71
70
  if retry_count > 0
72
71
  reconnect!
73
72
  retry_count -= 1
@@ -80,8 +79,6 @@ module Backburner
80
79
  end
81
80
  end
82
81
 
83
- protected
84
-
85
82
  # Attempt to ensure we're connected to allq if the missing method is
86
83
  # present in the delegate and we haven't shut down the connection on purpose
87
84
  # @raise [Beaneater::NotConnected] If allq fails to connect after multiple attempts.
@@ -93,16 +90,23 @@ module Backburner
93
90
  # Connects to a allq queue
94
91
  # @raise Beaneater::NotConnected if the connection cannot be established
95
92
  def connect!
96
- @allq_wrapper = Backburner::AllqWrapper.new(allq_addresses)
97
- __setobj__(@allq_wrapper)
93
+ @allq_wrapper = Backburner::AllQWrapper.new(allq_addresses)
98
94
  @allq_wrapper
99
95
  end
100
96
 
101
97
  def put(tube_name, data, opt)
102
98
  pri = (opt[:pri] || 5).to_i
103
- delay = opt[:delay].to_i
104
99
  ttr = (opt[:ttr] || 600).to_i
105
- @allq_wrapper.put2(data, pri, ttr, delay)
100
+
101
+ options = {
102
+ tube_name: tube_name,
103
+ pri: pri,
104
+ delay: opt[:delay].to_i,
105
+ ttr: ttr
106
+ }
107
+
108
+ options.merge!(opt)
109
+ @allq_wrapper.put(data, options)
106
110
  end
107
111
 
108
112
  def get(tube_name)
@@ -48,12 +48,7 @@ module Backburner
48
48
  return false unless res
49
49
  # Execute the job
50
50
  @hooks.around_hook_events(job_name, :around_perform, *args) do
51
- # We subtract one to ensure we timeout before beanstalkd does, except if:
52
- # a) ttr == 0, to support never timing out
53
- # b) ttr == 1, so that we don't accidentally set it to never time out
54
- # NB: A ttr of 1 will likely result in race conditions between
55
- # Backburner and beanstalkd and should probably be avoided
56
- timeout_job_after(task.ttr > 1 ? task.ttr - 1 : task.ttr) { job_class.perform(*args) }
51
+ job_class.perform(*args)
57
52
  end
58
53
  task.delete
59
54
  # Invoke after perform hook
@@ -1,3 +1,3 @@
1
1
  module Backburner
2
- VERSION = "1.0.5"
2
+ VERSION = "1.0.12"
3
3
  end
@@ -40,7 +40,7 @@ module Backburner
40
40
  connection.retryable do
41
41
  tube_name = expand_tube_name(queue || job_class)
42
42
  serialized_data = Backburner.configuration.job_serializer_proc.call(data)
43
- response = connection.put(serialized_data, :pri => pri, :delay => delay, :ttr => ttr)
43
+ response = connection.put(tube_name, serialized_data, :pri => pri, :delay => delay, :ttr => ttr, :shard_key => opts[:shard_key])
44
44
  end
45
45
  return nil unless Backburner::Hooks.invoke_hook_events(job_class, :after_enqueue, *args)
46
46
  ensure
@@ -129,7 +129,8 @@ module Backburner
129
129
  def work_one_job(conn = connection)
130
130
  begin
131
131
  job = reserve_job(conn)
132
- rescue Beaneater::TimedOutError => e
132
+ rescue Exception => e
133
+ sleep(rand*3)
133
134
  return
134
135
  end
135
136
 
@@ -147,20 +148,19 @@ module Backburner
147
148
  return
148
149
  end
149
150
 
150
- # NB: There's a slight chance here that the connection to beanstalkd has
151
+ # NB: There's a slight chance here that the connection to allq has
151
152
  # gone down between the time we reserved / processed the job and here.
152
- num_retries = job.stats.releases
153
+ num_retries = job.releases
153
154
  max_job_retries = resolve_max_job_retries(job.job_class)
154
155
  retry_status = "failed: attempt #{num_retries+1} of #{max_job_retries+1}"
155
- if num_retries < max_job_retries # retry again
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
- job.retry(num_retries + 1, delay)
159
- self.log_job_end(job.name, "#{retry_status}, retrying in #{delay}s") if job_started_at
160
- else # retries failed, bury
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
161
159
  job.bury
162
- self.log_job_end(job.name, "#{retry_status}, burying") if job_started_at
160
+ else
161
+ job.release(delay)
163
162
  end
163
+ self.log_job_end(job.name, "#{retry_status}, retrying in #{delay}s") if job_started_at
164
164
 
165
165
  handle_error(e, job.name, job.args, job)
166
166
  end
@@ -170,7 +170,7 @@ module Backburner
170
170
 
171
171
  # Return a new connection instance
172
172
  def new_connection
173
- Connection.new(Backburner.configuration.beanstalk_url) { |conn| Backburner::Hooks.invoke_hook_events(self, :on_reconnect, conn) }
173
+ Connection.new(Backburner.configuration.allq_url) { |conn| Backburner::Hooks.invoke_hook_events(self, :on_reconnect, conn) }
174
174
  end
175
175
 
176
176
  # Reserve a job from the watched queues
@@ -105,7 +105,7 @@ module Backburner
105
105
  # Process the tube settings
106
106
  # This overrides @tubes_data set by process_tube_names method. So a tube has name 'super_job:5'
107
107
  # and the tube class has setting queue_jobs_limit 10, the result limit will be 10
108
- # If the tube is known by existing beanstalkd queue, but not by class - skip it
108
+ # If the tube is known by existing allq queue, but not by class - skip it
109
109
  #
110
110
  def process_tube_options
111
111
  Backburner::Worker.known_queue_classes.each do |queue|
@@ -105,7 +105,7 @@ module Backburner
105
105
  # Process the tube settings
106
106
  # This overrides @tubes_data set by process_tube_names method. So a tube has name 'super_job:5:20:10'
107
107
  # and the tube class has setting queue_jobs_limit 10, the result limit will be 10
108
- # If the tube is known by existing beanstalkd queue, but not by class - skip it
108
+ # If the tube is known by existing allq queue, but not by class - skip it
109
109
  #
110
110
  def process_tube_options
111
111
  Backburner::Worker.known_queue_classes.each do |queue|
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.5
4
+ version: 1.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Malcolm
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-08 00:00:00.000000000 Z
11
+ date: 2021-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: allq_rest
@@ -100,7 +100,7 @@ dependencies:
100
100
  - - ">="
101
101
  - !ruby/object:Gem::Version
102
102
  version: '0'
103
- description: Beanstalk background job processing made easy
103
+ description: Allq background job processing made easy
104
104
  email:
105
105
  - jason@blitline.com
106
106
  executables:
@@ -169,7 +169,7 @@ files:
169
169
  - test/workers/simple_worker_test.rb
170
170
  - test/workers/threading_worker_test.rb
171
171
  - test/workers/threads_on_fork_worker_test.rb
172
- homepage: http://github.com/nesquena/backburner
172
+ homepage: http://github.com/blitline-dev/backburner-allq
173
173
  licenses:
174
174
  - MIT
175
175
  metadata: {}