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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 07932a16f900199549ba88c4eb68a9aee5bf79f3
4
- data.tar.gz: 697e7518ffaab1a98fa034aa309b2076392b47d9
3
+ metadata.gz: e3fff7e649a2c1b3cb5c79855466ffc591a1e89e
4
+ data.tar.gz: 65bbb33f63f9427a8c6b58961834e44baeac1334
5
5
  SHA512:
6
- metadata.gz: 3b7ef7a498830b6d6eff47fe5068abd2180b317ddc80cd3f6d4073dd0c7defcb6d74db05664f08e757a314674c3ee750d34c2327189408d92c5ba429b7796109
7
- data.tar.gz: 5559d5cd379dd854e4f1df50ecf8e3fdb8538af9a215f972dc65dd4434eb6caeeae803115687acd8a66c08fddb377e4efd018f45642e885f00459f53f700dc45
6
+ metadata.gz: 3324a9047a862ce798de1b78966ca4526b690fdee1ea17933d2cfa4f3c74f9abf9e63eaec91181aa48954b3da213fc94123e4dab52275029bd7859d7d62aaad7
7
+ data.tar.gz: e8b7a6b839014c1771dbc23c6fba4488c74338fef156bb2d272cb0718e0a51bf456553a4e98b880f89913a2607cea4411a4e197b2cce3ac146fe68ee0501a373
data/.gitignore CHANGED
@@ -1,21 +1,9 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
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/
@@ -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 process_event(event)
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
@@ -1,3 +1,3 @@
1
1
  module Workers
2
- VERSION = '0.4.0'
2
+ VERSION = '0.5.0'
3
3
  end
@@ -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 process_event; end
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
- return false
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
- true
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.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-07-20 00:00:00.000000000 Z
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