shoryuken 3.0.11 → 3.1.0

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: 245e3ba81adf78f01166faec0e8677ad325158c4
4
- data.tar.gz: e6742defd6bf3b887783345ff4c282680c6e2ca0
3
+ metadata.gz: 779c3e9c7f708f0a6dccb3e8b0c9f7e2490b25e1
4
+ data.tar.gz: bf260a2793ff8c07ddfb670832ba5f12af8d85d9
5
5
  SHA512:
6
- metadata.gz: ceb8790cd3b3ddc61ea36d09367e05cb42e5f195b90870e64642d1728ced6c2b94a5bb4d402db51b15da59c5db2f12852a1cc604ebf7fd6ac32259d8c71ab8f4
7
- data.tar.gz: f26dc1d67b5f9a7093cd97640bd7fccea45fdfd37197791e189d02af9ab1a18c7a58b4f5f172e5acf1e4f8655a98dc01823684c6104adb8800741bba8a50173c
6
+ metadata.gz: 1f3e7a4b668c929daa1b5424b7a8ab7f028238b3f6dfe0e812351991bbc37923b58491760df6e4ed4921624cd4954761daeac257c6a540fd193d160d121044de
7
+ data.tar.gz: 02f2bf2e813cbe1624ae83d16936196ecf523fe8d3773f9b0c39813aa0822d3c71fd273ee01a63072c20d86bf05f4c1a775eda3fae41cec4bf55ea567f772aef
data/.travis.yml CHANGED
@@ -4,6 +4,7 @@ rvm:
4
4
  - 2.1.0
5
5
  - 2.2.0
6
6
  - 2.3.3
7
+ - 2.4.1
7
8
 
8
9
  notifications:
9
10
  email:
data/CHANGELOG.md CHANGED
@@ -1,6 +1,17 @@
1
+ ## [v3.1.0] - 2017-07-02
2
+
3
+ - Add shoryuken sqs delete command
4
+ - [#395](https://github.com/phstc/shoryuken/pull/395)
5
+
6
+ - Add processing groups support; Concurrency per queue support
7
+ - [#389](https://github.com/phstc/shoryuken/pull/389)
8
+
9
+ - Terminate Shoryuken if the fetcher crashes
10
+ - [#389](https://github.com/phstc/shoryuken/pull/389)
11
+
1
12
  ## [v3.0.11] - 2017-06-24
2
13
 
3
- - Add shoryuken sqs create. Tell about sqs create, if queue not found.
14
+ - Add shoryuken sqs create command
4
15
  - [#388](https://github.com/phstc/shoryuken/pull/388)
5
16
 
6
17
  ## [v3.0.10] - 2017-06-24
@@ -8,7 +19,7 @@
8
19
  - Allow aws sdk v3
9
20
  - [#381](https://github.com/phstc/shoryuken/pull/381)
10
21
 
11
- - Allow configuring Rails via the config file
22
+ - Allow configuring Rails via the config file
12
23
  - [#387](https://github.com/phstc/shoryuken/pull/387)
13
24
 
14
25
  ## [v3.0.9] - 2017-06-05
data/Gemfile CHANGED
@@ -7,4 +7,5 @@ group :test do
7
7
  gem 'codeclimate-test-reporter', require: nil
8
8
  gem 'simplecov'
9
9
  gem 'multi_xml'
10
+ gem 'httparty'
10
11
  end
data/README.md CHANGED
@@ -1,35 +1,23 @@
1
1
  # Shoryuken
2
2
 
3
- ![](shoryuken.jpg)
3
+ ![Shoryuken](shoryuken.jpg)
4
4
 
5
- Shoryuken _sho-ryu-ken_ is a super-efficient [AWS SQS](https://aws.amazon.com/sqs/) thread-based message processor.
5
+ Shoryuken _sho-ryu-ken_ is a super-efficient [Amazon SQS](https://aws.amazon.com/sqs/) thread-based message processor.
6
6
 
7
7
  [![Build Status](https://travis-ci.org/phstc/shoryuken.svg)](https://travis-ci.org/phstc/shoryuken)
8
8
  [![Code Climate](https://codeclimate.com/github/phstc/shoryuken/badges/gpa.svg)](https://codeclimate.com/github/phstc/shoryuken)
9
9
 
10
10
  ## Key features
11
11
 
12
- ### Load balancing
13
-
14
- Yeah, Shoryuken load balances the messages consumption!
15
-
16
- ```yaml
17
- concurrency: 25
18
- delay: 0
19
- queues:
20
- - [high_priority, 6]
21
- - [normal_priority, 2]
22
- - [low_priority, 1]
23
- ```
24
-
25
- Or you can set them all to 1 for having the same priorities.
26
-
27
- - `concurrency` (default 25) is the number of threads you want to make available for processing.
28
- - `delay` (default to 0) is the number of seconds to pause fetching from an empty queue. SQS charges per request, pause checking empty queues for a while can be a cost efficient strategy.
29
-
30
- ### Fetch in batches
31
-
32
- To be even more performant and cost effective, Shoryuken fetches SQS messages in batches, so a single SQS request can fetch up to 10 messages.
12
+ - [Rails Active Job](https://github.com/phstc/shoryuken/wiki/Rails-Integration-Active-Job)
13
+ - [Queue Load balancing](https://github.com/phstc/shoryuken/wiki/Shoryuken-options#load-balancing)
14
+ - [Concurrency per queue](https://github.com/phstc/shoryuken/wiki/Processing-Groups)
15
+ - [Long Polling](https://github.com/phstc/shoryuken/wiki/Long-Polling)
16
+ - [Batch processing](https://github.com/phstc/shoryuken/wiki/Worker-options#batch)
17
+ - [Auto extend visibility timeout](https://github.com/phstc/shoryuken/wiki/Worker-options#auto_visibility_timeout)
18
+ - [Exponential backoff](https://github.com/phstc/shoryuken/wiki/Worker-options#retry_intervals)
19
+ - [Middleware support](https://github.com/phstc/shoryuken/wiki/Middleware)
20
+ - Amazon SQS CLI. See `shoryuken help sqs`
33
21
 
34
22
  ## Requirements
35
23
 
@@ -43,102 +31,19 @@ Add this line to your application's Gemfile:
43
31
  gem 'shoryuken'
44
32
  ```
45
33
 
46
- Or to get the latest updates:
47
-
48
- ```ruby
49
- gem 'shoryuken', github: 'phstc/shoryuken', branch: 'master'
50
- ```
51
-
52
34
  And then execute:
53
35
 
54
- $ bundle
55
-
56
- Or install it yourself as:
57
-
58
- $ gem install shoryuken
59
-
60
- ## Usage
61
-
62
- ### Worker class
63
-
64
- ```ruby
65
- class MyWorker
66
- include Shoryuken::Worker
67
-
68
- shoryuken_options queue: 'default', auto_delete: true
69
- # shoryuken_options queue: ->{ "#{ENV['environment']}_default" }
70
-
71
- # shoryuken_options body_parser: :json
72
- # shoryuken_options body_parser: ->(sqs_msg){ REXML::Document.new(sqs_msg.body) }
73
- # shoryuken_options body_parser: JSON
74
-
75
- def perform(sqs_msg, body)
76
- puts body
77
- end
78
- end
79
- ```
80
-
81
- [Check the Worker options documention](https://github.com/phstc/shoryuken/wiki/Worker-options).
82
-
83
- ### Sending a message
84
-
85
- [Check the Sending a message documentation](https://github.com/phstc/shoryuken/wiki/Sending-a-message)
86
-
87
- ### Middleware
88
-
89
- ```ruby
90
- class MyMiddleware
91
- def call(worker_instance, queue, sqs_msg, body)
92
- puts 'Before work'
93
- yield
94
- puts 'After work'
95
- end
96
- end
97
- ```
98
-
99
- [Check the Middleware documentation](https://github.com/phstc/shoryuken/wiki/Middleware).
100
-
101
- ### Shoryuken Configuration
102
-
103
- Sample configuration file `shoryuken.yml`.
104
-
105
- ```yaml
106
- concurrency: 25 # The number of allocated threads to process messages. Default 25
107
- delay: 0 # The delay in seconds to pause empty queues. Default 0
108
- queues:
109
- - [queue1, 1]
110
- - [queue2, 1]
111
- - [queue3, 1]
112
- ```
113
-
114
- #### AWS Configuration
115
-
116
- [Check the Configure AWS Client documentation](https://github.com/phstc/shoryuken/wiki/Configure-the-AWS-Client)
117
-
118
- ### Rails Integration
119
-
120
- [Check the Rails Integration Active Job documention](https://github.com/phstc/shoryuken/wiki/Rails-Integration-Active-Job).
121
-
122
- ### Start Shoryuken
123
-
124
36
  ```shell
125
- bundle exec shoryuken -r worker.rb -C shoryuken.yml
37
+ $ bundle
126
38
  ```
127
39
 
128
- For other options check `bundle exec shoryuken help start`
129
-
130
- #### SQS commands
131
-
132
- Check also some available SQS commands `bundle exec shoryuken help sqs`, such as:
40
+ ## Usage
133
41
 
134
- - `ls` list queues
135
- - `mv` move messages from one queue to another
136
- - `dump` dump messages from a queue into a JSON lines file
137
- - `requeue` requeue messages from a dump file
42
+ Check the [Getting Started](https://github.com/phstc/shoryuken/wiki/Getting-Started) page.
138
43
 
139
44
  ## More Information
140
45
 
141
- For more information on advanced topics such as signals (shutdown), ActiveJob integration, and so on please check the [Shoryuken Wiki](https://github.com/phstc/shoryuken/wiki).
46
+ For more information check the [wiki page](https://github.com/phstc/shoryuken/wiki).
142
47
 
143
48
  ## Credits
144
49
 
data/bin/cli/sqs.rb CHANGED
@@ -192,6 +192,13 @@ module Shoryuken
192
192
 
193
193
  say "Queue #{queue_name} was successfully created. Queue URL #{queue_url}", :green
194
194
  end
195
+
196
+ desc 'delete QUEUE-NAME', 'delete a queue'
197
+ def delete(queue_name)
198
+ sqs.delete_queue(queue_url: find_queue_url(queue_name))
199
+
200
+ say "Queue #{queue_name} was successfully delete", :green
201
+ end
195
202
  end
196
203
  end
197
204
  end
data/lib/shoryuken.rb CHANGED
@@ -20,185 +20,51 @@ require 'shoryuken/middleware/server/auto_delete'
20
20
  Shoryuken::Middleware::Server.autoload :AutoExtendVisibility, 'shoryuken/middleware/server/auto_extend_visibility'
21
21
  require 'shoryuken/middleware/server/exponential_backoff_retry'
22
22
  require 'shoryuken/middleware/server/timing'
23
- require 'shoryuken/polling'
23
+ require 'shoryuken/polling/base'
24
+ require 'shoryuken/polling/weighted_round_robin'
25
+ require 'shoryuken/polling/strict_priority'
24
26
  require 'shoryuken/manager'
25
27
  require 'shoryuken/launcher'
26
28
  require 'shoryuken/processor'
27
29
  require 'shoryuken/fetcher'
30
+ require 'shoryuken/options'
28
31
 
29
32
  module Shoryuken
30
- DEFAULTS = {
31
- concurrency: 25,
32
- queues: [],
33
- aws: {},
34
- delay: 0,
35
- timeout: 8,
36
- lifecycle_events: {
37
- startup: [],
38
- dispatch: [],
39
- quiet: [],
40
- shutdown: []
41
- },
42
- polling_strategy: Polling::WeightedRoundRobin
43
- }.freeze
44
-
45
- @@queues = []
46
- @@worker_registry = DefaultWorkerRegistry.new
47
- @@active_job_queue_name_prefixing = false
48
- @@sqs_client = nil
49
- @@sqs_client_receive_message_opts = {}
50
- @@start_callback = nil
51
- @@stop_callback = nil
52
-
53
- class << self
54
- def queues
55
- @@queues
56
- end
57
-
58
- def add_queue(queue, priority = 1)
59
- priority.times { queues << queue }
60
- end
61
-
62
- def worker_registry
63
- @@worker_registry
64
- end
65
-
66
- def worker_registry=(worker_registry)
67
- @@worker_registry = worker_registry
68
- end
69
-
70
- def start_callback
71
- @@start_callback
72
- end
73
-
74
- def start_callback=(start_callback)
75
- @@start_callback = start_callback
76
- end
77
-
78
- def stop_callback
79
- @@stop_callback
80
- end
81
-
82
- def stop_callback=(stop_callback)
83
- @@stop_callback = stop_callback
84
- end
85
-
86
- def active_job_queue_name_prefixing
87
- @@active_job_queue_name_prefixing
88
- end
89
-
90
- def active_job_queue_name_prefixing=(active_job_queue_name_prefixing)
91
- @@active_job_queue_name_prefixing = active_job_queue_name_prefixing
92
- end
93
-
94
- def sqs_client
95
- @@sqs_client ||= Aws::SQS::Client.new
96
- end
97
-
98
- def sqs_client=(sqs_client)
99
- @@sqs_client = sqs_client
100
- end
101
-
102
- def sqs_client_receive_message_opts
103
- @@sqs_client_receive_message_opts
104
- end
105
-
106
- def sqs_client_receive_message_opts=(sqs_client_receive_message_opts)
107
- @@sqs_client_receive_message_opts = sqs_client_receive_message_opts
108
- end
109
-
110
- def options
111
- @@options ||= DEFAULTS.dup
112
- end
113
-
114
- def logger
115
- Shoryuken::Logging.logger
116
- end
117
-
118
- def register_worker(*args)
119
- @@worker_registry.register_worker(*args)
120
- end
121
-
122
- def configure_server
123
- yield self if server?
124
- end
125
-
126
- def server_middleware
127
- @@server_chain ||= default_server_middleware
128
- yield @@server_chain if block_given?
129
- @@server_chain
130
- end
131
-
132
- def configure_client
133
- yield self unless server?
134
- end
135
-
136
- def client_middleware
137
- @@client_chain ||= default_client_middleware
138
- yield @@client_chain if block_given?
139
- @@client_chain
140
- end
141
-
142
- def default_worker_options
143
- @@default_worker_options ||= {
144
- 'queue' => 'default',
145
- 'delete' => false,
146
- 'auto_delete' => false,
147
- 'auto_visibility_timeout' => false,
148
- 'retry_intervals' => nil,
149
- 'batch' => false
150
- }
151
- end
152
-
153
- def default_worker_options=(default_worker_options)
154
- @@default_worker_options = default_worker_options
155
- end
156
-
157
- def on_start(&block)
158
- @@start_callback = block
159
- end
160
-
161
- def on_stop(&block)
162
- @@stop_callback = block
163
- end
164
-
165
- # Register a block to run at a point in the Shoryuken lifecycle.
166
- # :startup, :quiet or :shutdown are valid events.
167
- #
168
- # Shoryuken.configure_server do |config|
169
- # config.on(:shutdown) do
170
- # puts "Goodbye cruel world!"
171
- # end
172
- # end
173
- def on(event, &block)
174
- fail ArgumentError, "Symbols only please: #{event}" unless event.is_a?(Symbol)
175
- fail ArgumentError, "Invalid event name: #{event}" unless options[:lifecycle_events].key?(event)
176
- options[:lifecycle_events][event] << block
177
- end
178
-
179
- private
180
-
181
- def default_server_middleware
182
- Middleware::Chain.new do |m|
183
- m.add Middleware::Server::Timing
184
- m.add Middleware::Server::ExponentialBackoffRetry
185
- m.add Middleware::Server::AutoDelete
186
- m.add Middleware::Server::AutoExtendVisibility
187
- if defined?(::ActiveRecord::Base)
188
- require 'shoryuken/middleware/server/active_record'
189
- m.add Middleware::Server::ActiveRecord
190
- end
191
- end
192
- end
193
-
194
- def default_client_middleware
195
- Middleware::Chain.new
196
- end
197
-
198
- def server?
199
- defined?(Shoryuken::CLI)
200
- end
201
- end
33
+ extend SingleForwardable
34
+
35
+ def_delegators(
36
+ :'Shoryuken::Options',
37
+ :add_group,
38
+ :groups,
39
+ :add_queue,
40
+ :ungrouped_queues,
41
+ :worker_registry,
42
+ :worker_registry=,
43
+ :polling_strategy,
44
+ :start_callback,
45
+ :start_callback=,
46
+ :stop_callback,
47
+ :stop_callback=,
48
+ :active_job_queue_name_prefixing,
49
+ :active_job_queue_name_prefixing=,
50
+ :sqs_client,
51
+ :sqs_client=,
52
+ :sqs_client_receive_message_opts,
53
+ :sqs_client_receive_message_opts=,
54
+ :options,
55
+ :logger,
56
+ :register_worker,
57
+ :configure_server,
58
+ :server?,
59
+ :server_middleware,
60
+ :configure_client,
61
+ :client_middleware,
62
+ :default_worker_options,
63
+ :default_worker_options=,
64
+ :on_start,
65
+ :on_stop,
66
+ :on
67
+ )
202
68
  end
203
69
 
204
70
  require 'shoryuken/extensions/active_job_adapter' if defined?(::ActiveJob)