workers 0.2.1 → 0.2.2

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.
data/README.md CHANGED
@@ -22,7 +22,7 @@ Or install it yourself as:
22
22
  ## Parallel Map
23
23
 
24
24
  Parallel map is the simplest way to get started with the Workers gem.
25
- It is similar to Ruby's built in Array#map method except each element is mapped in parallel.
25
+ It is similar to Ruby's built-in Array#map method except each element is mapped in parallel.
26
26
 
27
27
  Workers.map([1, 2, 3, 4, 5]) { |i| i * i }
28
28
 
@@ -73,7 +73,7 @@ The main benefit is that you get to decide how you want to handle exceptions.
73
73
  group.tasks.each do |t|
74
74
  t.succeeded? # True or false (false if an exception occurred).
75
75
  t.failed? # True or false (true if an exception occurred).
76
- t.args # Input arguments (the value of i in this example).
76
+ t.input # Input value.
77
77
  t.result # Output value (the result of i * i in this example).
78
78
  t.exception # The exception if one exists.
79
79
  t.max_tries # Maximum number of attempts.
@@ -168,8 +168,9 @@ This effectively gives you direct access to a single event-driven thread.
168
168
 
169
169
  ## Pools
170
170
 
171
- As shown above, pools effectively allow a group of workers to share a work queue.
172
- They have a few additional methods described below:
171
+ Pools allow a group of workers to share a work queue.
172
+ The Workers gem has a default pool (Workers.pool) with 20 workers so in most cases you won't need to create your own.
173
+ Pools can be adjusted using the below methods:
173
174
 
174
175
  # Create a pool.
175
176
  pool = Workers::Pool.new
@@ -232,8 +233,9 @@ Timers provide a way to execute code in the future:
232
233
  ## Schedulers
233
234
 
234
235
  Schedulers are what trigger Timers to fire.
235
- The system has a global default scheduler which should meet most needs (Workers.scheduler).
236
- You can create additional or custom ones as necessary:
236
+ The Workers gem has a default scheduler (Workers.scheduler) so in most cases you won't need to create your own.
237
+ Schedulers execute timers using a pool of workers so make sure your timer block is thread safe.
238
+ You can create additional schedulers as necessary:
237
239
 
238
240
  # Create a workers pool with a larger than default thread count (optional).
239
241
  pool = Workers::Pool.new(:size => 100)
data/lib/workers/task.rb CHANGED
@@ -2,7 +2,7 @@ module Workers
2
2
  class Task
3
3
  include Workers::Helpers
4
4
 
5
- attr_reader :args
5
+ attr_reader :input
6
6
  attr_reader :result
7
7
  attr_reader :exception
8
8
  attr_reader :state
@@ -11,7 +11,7 @@ module Workers
11
11
 
12
12
  def initialize(options = {})
13
13
  @logger = Workers::LogProxy.new(options[:logger])
14
- @args = options[:args] || []
14
+ @input = options[:input] || []
15
15
  @perform = options[:perform] || raise('Perform callback is required.')
16
16
  @finished = options[:finished]
17
17
  @max_tries = options[:max_tries] || 1
@@ -32,7 +32,7 @@ module Workers
32
32
  @tries += 1
33
33
 
34
34
  begin
35
- @result = @perform.call(*@args)
35
+ @result = @perform.call(@input)
36
36
  @state = :succeeded
37
37
  @exception = nil
38
38
  rescue Exception => e
@@ -58,7 +58,7 @@ module Workers
58
58
 
59
59
  def map(inputs, options = {}, &block)
60
60
  inputs.each do |input|
61
- add(:args => input, :max_tries => options[:max_tries]) do |i|
61
+ add(:input => input, :max_tries => options[:max_tries]) do |i|
62
62
  block.call(i)
63
63
  end
64
64
  end
@@ -66,7 +66,7 @@ module Workers
66
66
  run
67
67
 
68
68
  if (failure = failures[0])
69
- a = failure.args.inspect
69
+ a = failure.input.inspect
70
70
  m = failure.exception.message
71
71
  b = failure.exception.backtrace.join("\n")
72
72
 
@@ -1,3 +1,3 @@
1
1
  module Workers
2
- VERSION = '0.2.1'
2
+ VERSION = '0.2.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: workers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-02 00:00:00.000000000 Z
12
+ date: 2013-06-03 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Workers is a Ruby gem for performing work in background threads.
15
15
  email:
@@ -56,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
56
56
  version: '0'
57
57
  requirements: []
58
58
  rubyforge_project:
59
- rubygems_version: 1.8.25
59
+ rubygems_version: 1.8.24
60
60
  signing_key:
61
61
  specification_version: 3
62
62
  summary: Workers is a Ruby gem for performing work in background threads. Design goals