workers 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +9 -21
- data/.ruby-version +1 -0
- data/README.md +4 -1
- data/lib/workers/version.rb +1 -1
- data/lib/workers/worker.rb +13 -6
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e3fff7e649a2c1b3cb5c79855466ffc591a1e89e
|
4
|
+
data.tar.gz: 65bbb33f63f9427a8c6b58961834e44baeac1334
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3324a9047a862ce798de1b78966ca4526b690fdee1ea17933d2cfa4f3c74f9abf9e63eaec91181aa48954b3da213fc94123e4dab52275029bd7859d7d62aaad7
|
7
|
+
data.tar.gz: e8b7a6b839014c1771dbc23c6fba4488c74338fef156bb2d272cb0718e0a51bf456553a4e98b880f89913a2607cea4411a4e197b2cce3ac146fe68ee0501a373
|
data/.gitignore
CHANGED
@@ -1,21 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
.
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
doc/
|
11
|
-
lib/bundler/man
|
12
|
-
pkg
|
13
|
-
rdoc
|
14
|
-
spec/reports
|
15
|
-
test/tmp
|
16
|
-
test/version_tmp
|
17
|
-
tmp
|
18
|
-
.rvmrc
|
19
|
-
*.swp
|
20
|
-
.ruby-version
|
21
|
-
.ruby-gemset
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/Gemfile.lock
|
4
|
+
/_yardoc/
|
5
|
+
/coverage/
|
6
|
+
/doc/
|
7
|
+
/pkg/
|
8
|
+
/spec/reports/
|
9
|
+
/tmp/
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.2.2
|
data/README.md
CHANGED
@@ -147,9 +147,10 @@ Failing to handle exceptions will result in dead workers so you must rescue them
|
|
147
147
|
The Worker class is designed to be customized through inheritence and its event system:
|
148
148
|
|
149
149
|
# Create a subclass that handles custom events.
|
150
|
+
# Super is called to handle built-in events such as perform and shutdown.
|
150
151
|
class CustomWorker < Workers::Worker
|
151
152
|
private
|
152
|
-
def
|
153
|
+
def event_handler(event)
|
153
154
|
case event.command
|
154
155
|
when :my_custom
|
155
156
|
begin
|
@@ -158,6 +159,8 @@ The Worker class is designed to be customized through inheritence and its event
|
|
158
159
|
rescue Exception => e
|
159
160
|
puts "This is a very sad program."
|
160
161
|
end
|
162
|
+
else
|
163
|
+
super(event)
|
161
164
|
end
|
162
165
|
end
|
163
166
|
end
|
data/lib/workers/version.rb
CHANGED
data/lib/workers/worker.rb
CHANGED
@@ -10,6 +10,7 @@ module Workers
|
|
10
10
|
@thread = Thread.new { start_event_loop }
|
11
11
|
@exception_callback = options[:on_exception]
|
12
12
|
@die_on_exception = options.include?(:die_on_exception) ? options[:die_on_exception] : true
|
13
|
+
@run = true
|
13
14
|
|
14
15
|
nil
|
15
16
|
end
|
@@ -62,26 +63,32 @@ module Workers
|
|
62
63
|
private
|
63
64
|
|
64
65
|
def start_event_loop
|
65
|
-
while
|
66
|
+
while @run
|
67
|
+
process_event
|
68
|
+
end
|
66
69
|
end
|
67
70
|
|
68
71
|
def process_event
|
69
72
|
event = @input_queue.pop
|
73
|
+
event_handler(event)
|
74
|
+
rescue Exception => e
|
75
|
+
exception_handler(e)
|
76
|
+
end
|
70
77
|
|
78
|
+
# Override this method to handle custom events.
|
79
|
+
# Make sure you call super(event) if want to built-in events to work.
|
80
|
+
def event_handler(event)
|
71
81
|
case event.command
|
72
82
|
when :shutdown
|
73
83
|
shutdown_handler(event)
|
74
|
-
|
84
|
+
@run = false
|
75
85
|
when :perform
|
76
86
|
perform_handler(event)
|
77
87
|
else
|
78
88
|
raise Workers::UnknownEventError, "Unhandled event (#{event.inspect})."
|
79
89
|
end
|
80
90
|
|
81
|
-
|
82
|
-
rescue Exception => e
|
83
|
-
exception_handler(e)
|
84
|
-
true
|
91
|
+
nil
|
85
92
|
end
|
86
93
|
|
87
94
|
def shutdown_handler(event)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: workers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chad Remesch
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -60,6 +60,7 @@ extensions: []
|
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
62
|
- ".gitignore"
|
63
|
+
- ".ruby-version"
|
63
64
|
- ".travis.yml"
|
64
65
|
- Gemfile
|
65
66
|
- LICENSE.txt
|