toiler 0.3.6 → 0.4.0.beta1
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 +4 -4
- data/.gitignore +35 -35
- data/.gitmodules +4 -4
- data/.ruby-version +1 -1
- data/Gemfile +9 -9
- data/Gemfile.lock +41 -41
- data/LICENSE +6 -6
- data/README.md +125 -125
- data/Rakefile +1 -1
- data/bin/toiler +12 -12
- data/lib/toiler.rb +55 -55
- data/lib/toiler/actor/fetcher.rb +116 -116
- data/lib/toiler/actor/processor.rb +124 -123
- data/lib/toiler/actor/supervisor.rb +55 -55
- data/lib/toiler/actor/utils/actor_logging.rb +28 -28
- data/lib/toiler/aws/message.rb +64 -64
- data/lib/toiler/aws/queue.rb +61 -61
- data/lib/toiler/cli.rb +164 -164
- data/lib/toiler/utils/argument_parser.rb +50 -50
- data/lib/toiler/utils/environment_loader.rb +104 -104
- data/lib/toiler/utils/logging.rb +41 -41
- data/lib/toiler/version.rb +4 -4
- data/lib/toiler/worker.rb +62 -62
- data/toiler.gemspec +30 -30
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a4ced1103b95b851ceefc678c709faf6ed6f458e
|
4
|
+
data.tar.gz: ca7069d2a1ac054ea3bb7e5bb78c2effb8c08cfd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f070535678f3af853ad2835c42a69bf95e60cff53f137f7dd34b232f393df8d89b6b8e0679cc6999e9a3d14cdeac063d3676a9ca865357c07976c33fb5261aa1
|
7
|
+
data.tar.gz: a89273d951335f6b7916f19ca7f620365d2654228bd261a3ad41c3397034e40b76e429fc38c47facc90073044843de9ce3be0f17f4a904aeddd09554c74b0701
|
data/.gitignore
CHANGED
@@ -1,35 +1,35 @@
|
|
1
|
-
*.gem
|
2
|
-
*.rbc
|
3
|
-
/.config
|
4
|
-
/coverage/
|
5
|
-
/InstalledFiles
|
6
|
-
/pkg/
|
7
|
-
/spec/reports/
|
8
|
-
/test/tmp/
|
9
|
-
/test/version_tmp/
|
10
|
-
/tmp/
|
11
|
-
|
12
|
-
## Specific to RubyMotion:
|
13
|
-
.dat*
|
14
|
-
.repl_history
|
15
|
-
build/
|
16
|
-
|
17
|
-
## Documentation cache and generated files:
|
18
|
-
/.yardoc/
|
19
|
-
/_yardoc/
|
20
|
-
/doc/
|
21
|
-
/rdoc/
|
22
|
-
|
23
|
-
## Environment normalisation:
|
24
|
-
/.bundle/
|
25
|
-
/vendor/bundle
|
26
|
-
/lib/bundler/man/
|
27
|
-
|
28
|
-
# for a library or gem, you might want to ignore these files since the code is
|
29
|
-
# intended to run in multiple environments; otherwise, check them in:
|
30
|
-
# Gemfile.lock
|
31
|
-
# .ruby-version
|
32
|
-
# .ruby-gemset
|
33
|
-
|
34
|
-
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
35
|
-
.rvmrc
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
|
12
|
+
## Specific to RubyMotion:
|
13
|
+
.dat*
|
14
|
+
.repl_history
|
15
|
+
build/
|
16
|
+
|
17
|
+
## Documentation cache and generated files:
|
18
|
+
/.yardoc/
|
19
|
+
/_yardoc/
|
20
|
+
/doc/
|
21
|
+
/rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
/.bundle/
|
25
|
+
/vendor/bundle
|
26
|
+
/lib/bundler/man/
|
27
|
+
|
28
|
+
# for a library or gem, you might want to ignore these files since the code is
|
29
|
+
# intended to run in multiple environments; otherwise, check them in:
|
30
|
+
# Gemfile.lock
|
31
|
+
# .ruby-version
|
32
|
+
# .ruby-gemset
|
33
|
+
|
34
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
35
|
+
.rvmrc
|
data/.gitmodules
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
[submodule "celluloid-task-pooledfiber"]
|
2
|
-
path = celluloid-task-pooledfiber
|
3
|
-
url = git@github.com:celluloid/celluloid-task-pooledfiber.git
|
4
|
-
branch = 0.2.0-prerelease
|
1
|
+
[submodule "celluloid-task-pooledfiber"]
|
2
|
+
path = celluloid-task-pooledfiber
|
3
|
+
url = git@github.com:celluloid/celluloid-task-pooledfiber.git
|
4
|
+
branch = 0.2.0-prerelease
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.2.2
|
1
|
+
2.2.2
|
data/Gemfile
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
gem 'concurrent-ruby', '~> 1.0.0'
|
4
|
-
gem 'concurrent-ruby-edge', '~> 0.2.0'
|
5
|
-
gem 'aws-sdk', '~> 2.2'
|
6
|
-
|
7
|
-
group :development do
|
8
|
-
gem 'rubocop'
|
9
|
-
end
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem 'concurrent-ruby', '~> 1.0.0'
|
4
|
+
gem 'concurrent-ruby-edge', '~> 0.2.0'
|
5
|
+
gem 'aws-sdk', '~> 2.2'
|
6
|
+
|
7
|
+
group :development do
|
8
|
+
gem 'rubocop'
|
9
|
+
end
|
data/Gemfile.lock
CHANGED
@@ -1,41 +1,41 @@
|
|
1
|
-
GEM
|
2
|
-
remote: https://rubygems.org/
|
3
|
-
specs:
|
4
|
-
ast (2.2.0)
|
5
|
-
aws-sdk (2.3.7)
|
6
|
-
aws-sdk-resources (= 2.3.7)
|
7
|
-
aws-sdk-core (2.3.7)
|
8
|
-
jmespath (~> 1.0)
|
9
|
-
aws-sdk-resources (2.3.7)
|
10
|
-
aws-sdk-core (= 2.3.7)
|
11
|
-
concurrent-ruby (1.0.2)
|
12
|
-
concurrent-ruby-edge (0.2.2)
|
13
|
-
concurrent-ruby (~> 1.0.2)
|
14
|
-
jmespath (1.2.4)
|
15
|
-
json_pure (>= 1.8.1)
|
16
|
-
json_pure (1.8.3)
|
17
|
-
parser (2.3.1.0)
|
18
|
-
ast (~> 2.2)
|
19
|
-
powerpack (0.1.1)
|
20
|
-
rainbow (2.1.0)
|
21
|
-
rubocop (0.40.0)
|
22
|
-
parser (>= 2.3.1.0, < 3.0)
|
23
|
-
powerpack (~> 0.1)
|
24
|
-
rainbow (>= 1.99.1, < 3.0)
|
25
|
-
ruby-progressbar (~> 1.7)
|
26
|
-
unicode-display_width (~> 1.0, >= 1.0.1)
|
27
|
-
ruby-progressbar (1.8.1)
|
28
|
-
unicode-display_width (1.0.5)
|
29
|
-
|
30
|
-
PLATFORMS
|
31
|
-
ruby
|
32
|
-
x64-mingw32
|
33
|
-
|
34
|
-
DEPENDENCIES
|
35
|
-
aws-sdk (~> 2.2)
|
36
|
-
concurrent-ruby (~> 1.0.0)
|
37
|
-
concurrent-ruby-edge (~> 0.2.0)
|
38
|
-
rubocop
|
39
|
-
|
40
|
-
BUNDLED WITH
|
41
|
-
1.11.2
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
ast (2.2.0)
|
5
|
+
aws-sdk (2.3.7)
|
6
|
+
aws-sdk-resources (= 2.3.7)
|
7
|
+
aws-sdk-core (2.3.7)
|
8
|
+
jmespath (~> 1.0)
|
9
|
+
aws-sdk-resources (2.3.7)
|
10
|
+
aws-sdk-core (= 2.3.7)
|
11
|
+
concurrent-ruby (1.0.2)
|
12
|
+
concurrent-ruby-edge (0.2.2)
|
13
|
+
concurrent-ruby (~> 1.0.2)
|
14
|
+
jmespath (1.2.4)
|
15
|
+
json_pure (>= 1.8.1)
|
16
|
+
json_pure (1.8.3)
|
17
|
+
parser (2.3.1.0)
|
18
|
+
ast (~> 2.2)
|
19
|
+
powerpack (0.1.1)
|
20
|
+
rainbow (2.1.0)
|
21
|
+
rubocop (0.40.0)
|
22
|
+
parser (>= 2.3.1.0, < 3.0)
|
23
|
+
powerpack (~> 0.1)
|
24
|
+
rainbow (>= 1.99.1, < 3.0)
|
25
|
+
ruby-progressbar (~> 1.7)
|
26
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
27
|
+
ruby-progressbar (1.8.1)
|
28
|
+
unicode-display_width (1.0.5)
|
29
|
+
|
30
|
+
PLATFORMS
|
31
|
+
ruby
|
32
|
+
x64-mingw32
|
33
|
+
|
34
|
+
DEPENDENCIES
|
35
|
+
aws-sdk (~> 2.2)
|
36
|
+
concurrent-ruby (~> 1.0.0)
|
37
|
+
concurrent-ruby-edge (~> 0.2.0)
|
38
|
+
rubocop
|
39
|
+
|
40
|
+
BUNDLED WITH
|
41
|
+
1.11.2
|
data/LICENSE
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
Copyright (c) Sebastian Schepens
|
2
|
-
|
3
|
-
Toiler is an Open Source project licensed under the terms of
|
4
|
-
the LGPLv3 license. Please see <http://www.gnu.org/licenses/lgpl-3.0.html>
|
5
|
-
for license text.
|
6
|
-
|
1
|
+
Copyright (c) Sebastian Schepens
|
2
|
+
|
3
|
+
Toiler is an Open Source project licensed under the terms of
|
4
|
+
the LGPLv3 license. Please see <http://www.gnu.org/licenses/lgpl-3.0.html>
|
5
|
+
for license text.
|
6
|
+
|
data/README.md
CHANGED
@@ -1,125 +1,125 @@
|
|
1
|
-
##Toiler
|
2
|
-
Toiler is a AWS SQS long-polling thread-based message processor.
|
3
|
-
It's based on [shoryuken](https://github.com/phstc/shoryuken) but takes
|
4
|
-
a different approach at loadbalancing and uses long-polling.
|
5
|
-
|
6
|
-
##Features
|
7
|
-
###Concurrency
|
8
|
-
Toiler allows to specify the amount of processors (threads) that should be spawned for each queue.
|
9
|
-
Instead of [shoryuken's](https://github.com/phstc/shoryuken) loadbalancing approach, Toiler delegates this work to the kernel scheduling threads.
|
10
|
-
|
11
|
-
Because Toiler uses threads to provide concurrency, **each thread instatiates a new worker**, as it should be expected, so please **use class variables to store shared variables like clients**.
|
12
|
-
|
13
|
-
###Long-Polling
|
14
|
-
A Fetcher thread is spawned for each queue.
|
15
|
-
Fetchers are resposible for polling SQS and retreiving messages.
|
16
|
-
They are optimised to not bring more messages than the amount of processors avaiable for such queue.
|
17
|
-
By long-polling fetchers wait for a configurable amount of time for messages to become available on a single request, this prevents unneccesarilly requesting messages when there are none.
|
18
|
-
|
19
|
-
###Message Parsing
|
20
|
-
Workers can configure a parser Class or Proc to parse an SQS message body before being processed.
|
21
|
-
|
22
|
-
###Batches
|
23
|
-
Toiler allows a Worker to be able to receive a batch of messages instead of a single one.
|
24
|
-
|
25
|
-
###Auto Visibility Extension
|
26
|
-
Toiler has the ability to automatically extend the visibility timeout of and SQS message to prevent the message from re-entering the queue if processing of such message is taking longer than the queue's visibility timeout.
|
27
|
-
|
28
|
-
##Instalation
|
29
|
-
|
30
|
-
Add this line to your application's Gemfile:
|
31
|
-
|
32
|
-
```ruby
|
33
|
-
gem 'toiler'
|
34
|
-
```
|
35
|
-
|
36
|
-
And then execute:
|
37
|
-
|
38
|
-
$ bundle
|
39
|
-
|
40
|
-
Or install it yourself as:
|
41
|
-
|
42
|
-
$ gem install toiler
|
43
|
-
|
44
|
-
## Usage
|
45
|
-
|
46
|
-
### Worker class
|
47
|
-
|
48
|
-
```ruby
|
49
|
-
class MyWorker
|
50
|
-
include Toiler::Worker
|
51
|
-
|
52
|
-
toiler_options queue: 'default', concurrency: 5, auto_delete: true
|
53
|
-
toiler_options parser: :json
|
54
|
-
|
55
|
-
# toiler_options parser: ->(sqs_msg){ REXML::Document.new(sqs_msg.body) }
|
56
|
-
# toiler_options parser: MultiJson
|
57
|
-
# toiler_options auto_visibility_timeout: true
|
58
|
-
# toiler_options batch: true
|
59
|
-
|
60
|
-
#Example connection client that should be shared across all instances of MyWorker
|
61
|
-
@@client = ConnectionClient.new
|
62
|
-
|
63
|
-
def initialize
|
64
|
-
@last_message = nil
|
65
|
-
end
|
66
|
-
|
67
|
-
def perform(sqs_msg, body)
|
68
|
-
#Workers are thread safe, yay!
|
69
|
-
#Each worker instance is assured to be processing only one message at a time
|
70
|
-
@last_message = sqs_msg
|
71
|
-
puts body
|
72
|
-
end
|
73
|
-
end
|
74
|
-
```
|
75
|
-
|
76
|
-
### Configuration
|
77
|
-
|
78
|
-
```yaml
|
79
|
-
aws:
|
80
|
-
access_key_id: ... # or <%= ENV['AWS_ACCESS_KEY_ID'] %>
|
81
|
-
secret_access_key: ... # or <%= ENV['AWS_SECRET_ACCESS_KEY'] %>
|
82
|
-
region: us-east-1 # or <%= ENV['AWS_REGION'] %>
|
83
|
-
wait: 20 # The time in seconds to wait for messages during long-polling
|
84
|
-
```
|
85
|
-
|
86
|
-
### Rails Integration
|
87
|
-
|
88
|
-
You can tell Toiler to load your Rails application by passing the `-R` or `--rails` flag to the "toiler" command.
|
89
|
-
|
90
|
-
If you load Rails, and assuming your workers are located in the `app/workers` directory, they will be auto-loaded. This means you don't need to require them explicitly with `-r`.
|
91
|
-
|
92
|
-
|
93
|
-
### Start Toiler
|
94
|
-
|
95
|
-
```shell
|
96
|
-
bundle exec toiler -r worker.rb -C toiler.yml
|
97
|
-
```
|
98
|
-
|
99
|
-
Other options:
|
100
|
-
|
101
|
-
```bash
|
102
|
-
toiler --help
|
103
|
-
|
104
|
-
-d, --daemon Daemonize process
|
105
|
-
-r, --require [PATH|DIR] Location of the worker
|
106
|
-
-C, --config PATH Path to YAML config file
|
107
|
-
-R, --rails Load Rails
|
108
|
-
-L, --logfile PATH Path to writable logfile
|
109
|
-
-P, --pidfile PATH Path to pidfile
|
110
|
-
-v, --verbose Print more verbose output
|
111
|
-
-h, --help Show help
|
112
|
-
```
|
113
|
-
|
114
|
-
|
115
|
-
## Credits
|
116
|
-
|
117
|
-
Much of the credit goes to [Pablo Cantero](https://github.com/phstc), creator of [Shoryuken](https://github.com/phstc/shoryuken), and [everybody who contributed to it](https://github.com/phstc/shoryuken/graphs/contributors).
|
118
|
-
|
119
|
-
## Contributing
|
120
|
-
|
121
|
-
1. Fork it ( https://github.com/sschepens/toiler/fork )
|
122
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
123
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
124
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
125
|
-
5. Create a new Pull Request
|
1
|
+
##Toiler
|
2
|
+
Toiler is a AWS SQS long-polling thread-based message processor.
|
3
|
+
It's based on [shoryuken](https://github.com/phstc/shoryuken) but takes
|
4
|
+
a different approach at loadbalancing and uses long-polling.
|
5
|
+
|
6
|
+
##Features
|
7
|
+
###Concurrency
|
8
|
+
Toiler allows to specify the amount of processors (threads) that should be spawned for each queue.
|
9
|
+
Instead of [shoryuken's](https://github.com/phstc/shoryuken) loadbalancing approach, Toiler delegates this work to the kernel scheduling threads.
|
10
|
+
|
11
|
+
Because Toiler uses threads to provide concurrency, **each thread instatiates a new worker**, as it should be expected, so please **use class variables to store shared variables like clients**.
|
12
|
+
|
13
|
+
###Long-Polling
|
14
|
+
A Fetcher thread is spawned for each queue.
|
15
|
+
Fetchers are resposible for polling SQS and retreiving messages.
|
16
|
+
They are optimised to not bring more messages than the amount of processors avaiable for such queue.
|
17
|
+
By long-polling fetchers wait for a configurable amount of time for messages to become available on a single request, this prevents unneccesarilly requesting messages when there are none.
|
18
|
+
|
19
|
+
###Message Parsing
|
20
|
+
Workers can configure a parser Class or Proc to parse an SQS message body before being processed.
|
21
|
+
|
22
|
+
###Batches
|
23
|
+
Toiler allows a Worker to be able to receive a batch of messages instead of a single one.
|
24
|
+
|
25
|
+
###Auto Visibility Extension
|
26
|
+
Toiler has the ability to automatically extend the visibility timeout of and SQS message to prevent the message from re-entering the queue if processing of such message is taking longer than the queue's visibility timeout.
|
27
|
+
|
28
|
+
##Instalation
|
29
|
+
|
30
|
+
Add this line to your application's Gemfile:
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
gem 'toiler'
|
34
|
+
```
|
35
|
+
|
36
|
+
And then execute:
|
37
|
+
|
38
|
+
$ bundle
|
39
|
+
|
40
|
+
Or install it yourself as:
|
41
|
+
|
42
|
+
$ gem install toiler
|
43
|
+
|
44
|
+
## Usage
|
45
|
+
|
46
|
+
### Worker class
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
class MyWorker
|
50
|
+
include Toiler::Worker
|
51
|
+
|
52
|
+
toiler_options queue: 'default', concurrency: 5, auto_delete: true
|
53
|
+
toiler_options parser: :json
|
54
|
+
|
55
|
+
# toiler_options parser: ->(sqs_msg){ REXML::Document.new(sqs_msg.body) }
|
56
|
+
# toiler_options parser: MultiJson
|
57
|
+
# toiler_options auto_visibility_timeout: true
|
58
|
+
# toiler_options batch: true
|
59
|
+
|
60
|
+
#Example connection client that should be shared across all instances of MyWorker
|
61
|
+
@@client = ConnectionClient.new
|
62
|
+
|
63
|
+
def initialize
|
64
|
+
@last_message = nil
|
65
|
+
end
|
66
|
+
|
67
|
+
def perform(sqs_msg, body)
|
68
|
+
#Workers are thread safe, yay!
|
69
|
+
#Each worker instance is assured to be processing only one message at a time
|
70
|
+
@last_message = sqs_msg
|
71
|
+
puts body
|
72
|
+
end
|
73
|
+
end
|
74
|
+
```
|
75
|
+
|
76
|
+
### Configuration
|
77
|
+
|
78
|
+
```yaml
|
79
|
+
aws:
|
80
|
+
access_key_id: ... # or <%= ENV['AWS_ACCESS_KEY_ID'] %>
|
81
|
+
secret_access_key: ... # or <%= ENV['AWS_SECRET_ACCESS_KEY'] %>
|
82
|
+
region: us-east-1 # or <%= ENV['AWS_REGION'] %>
|
83
|
+
wait: 20 # The time in seconds to wait for messages during long-polling
|
84
|
+
```
|
85
|
+
|
86
|
+
### Rails Integration
|
87
|
+
|
88
|
+
You can tell Toiler to load your Rails application by passing the `-R` or `--rails` flag to the "toiler" command.
|
89
|
+
|
90
|
+
If you load Rails, and assuming your workers are located in the `app/workers` directory, they will be auto-loaded. This means you don't need to require them explicitly with `-r`.
|
91
|
+
|
92
|
+
|
93
|
+
### Start Toiler
|
94
|
+
|
95
|
+
```shell
|
96
|
+
bundle exec toiler -r worker.rb -C toiler.yml
|
97
|
+
```
|
98
|
+
|
99
|
+
Other options:
|
100
|
+
|
101
|
+
```bash
|
102
|
+
toiler --help
|
103
|
+
|
104
|
+
-d, --daemon Daemonize process
|
105
|
+
-r, --require [PATH|DIR] Location of the worker
|
106
|
+
-C, --config PATH Path to YAML config file
|
107
|
+
-R, --rails Load Rails
|
108
|
+
-L, --logfile PATH Path to writable logfile
|
109
|
+
-P, --pidfile PATH Path to pidfile
|
110
|
+
-v, --verbose Print more verbose output
|
111
|
+
-h, --help Show help
|
112
|
+
```
|
113
|
+
|
114
|
+
|
115
|
+
## Credits
|
116
|
+
|
117
|
+
Much of the credit goes to [Pablo Cantero](https://github.com/phstc), creator of [Shoryuken](https://github.com/phstc/shoryuken), and [everybody who contributed to it](https://github.com/phstc/shoryuken/graphs/contributors).
|
118
|
+
|
119
|
+
## Contributing
|
120
|
+
|
121
|
+
1. Fork it ( https://github.com/sschepens/toiler/fork )
|
122
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
123
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
124
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
125
|
+
5. Create a new Pull Request
|