threasy 0.3.2 → 0.4.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 24769445131b62b227817a4cd7eacf4682e3855e
4
- data.tar.gz: f5d317aee9b0de3f7b4989526b8716738f9f45fb
3
+ metadata.gz: ec726270eb6e569d255112041fd86e32edba66a7
4
+ data.tar.gz: fc7b534b55f290a4f74de5559488a2496b0a19d6
5
5
  SHA512:
6
- metadata.gz: a2b47d68b23493aa3a66e6ef6a5369c06d5301a07cb952a9a1b77f322991176f7d4052ec9dd97f533be0fb31391460fce429d6cdda3abf95be8e7b84db728c6e
7
- data.tar.gz: db3c0cebce5e18bc13854112782d91c273c34f3a14c0e6b1a9a2c94360f6b0d6ecd4e5e2173bf8fa30ca8bc2e514a3292ce6fbfcfd0d80b2700d6f12d4440cc9
6
+ metadata.gz: 37aea98e1bf6102d0bd31a9c9e312ce5c8df512c18cbf66abcdb755af3997b0aa61cdf014ed91768ab8c063ad0801345eb0ed463dbfbe20b9e87480718aa56f7
7
+ data.tar.gz: e2be7cc6c78f8e06d81ecc6ed18426fdbfaf63eaf59ccc2192e856252f3f6f5b798b029e25f8203277e4a9b08667c99dbfe2c5d7ebd37c159e274d83eb739dac
data/README.md CHANGED
@@ -49,12 +49,14 @@ Or install it yourself as:
49
49
 
50
50
  ```ruby
51
51
  # Use a block
52
- Threasy.enqueue{ puts "This will happen in the background" }
52
+ Threasy.enqueue { puts "This will happen in the background" }
53
53
 
54
- # Use an object that responds to #perform or #call
54
+ # Use an object that responds to `perform` or `call`
55
55
  Threasy.enqueue MyJob.new(1,2,3)
56
56
  ```
57
57
 
58
+ Jobs are placed in a work queue. Worker threads are spun up to process jobs as the queue grows.
59
+
58
60
  ### `schedule`
59
61
 
60
62
  Puts a job onto the schedule. Once the scheduler sees a job is due for processessing, it is enqueued into the work queue to be processed like any other job.
@@ -75,9 +77,35 @@ Threasy.schedule(:in => 5.minutes) { puts "In the background, 5 minutes from now
75
77
  Threasy.schedule(MyJob.new(1,2,3), every: 5.minutes)
76
78
  ```
77
79
 
80
+ ### `schedules`
81
+
82
+ Returns the default instance of [`Threasy::Schedule`][schedule], which manages scheduled jobs.
83
+
84
+ ### `work`
85
+
86
+ Returns the default instance of [`Threasy::Work`][work], which manages the work queue and worker threads.
87
+
88
+ ### `config`
89
+
90
+ Returns the default instance of [`Threasy::Config`][config], which manages runtime configuration options.
91
+
92
+ `Threasy.config` can also accept a block and will yield the [`Threasy::Config`][config] instance.
93
+
94
+ ```ruby
95
+ Threasy.config do |c|
96
+ c.max_sleep = 5.minutes
97
+ c.max_overdue = 1.hour
98
+ c.max_workers = 8
99
+ end
100
+ ```
101
+
102
+ [schedule]: lib/threasy/schedule.rb
103
+ [work]: lib/threasy/work.rb
104
+ [config]: lib/threasy/config.rb
105
+
78
106
  ## Contributing
79
107
 
80
- 1. Fork it ( http://github.com/<my-github-username>/threasy/fork )
108
+ 1. Fork it ( http://github.com/carlzulauf/threasy/fork )
81
109
  2. Create your feature branch (`git checkout -b my-new-feature`)
82
110
  3. Commit your changes (`git commit -am 'Add some feature'`)
83
111
  4. Push to the branch (`git push origin my-new-feature`)
@@ -11,7 +11,7 @@ module Threasy
11
11
  # and should not be created by hand.
12
12
  #
13
13
  # See `Threasy::Schedule#add`
14
- attr_accessor :schedule, :work, :job, :at, :repeat
14
+ attr_accessor :schedule, :work, :job, :at, :repeat, :times
15
15
 
16
16
  def initialize(job, options = {})
17
17
  self.schedule = options.fetch(:schedule) { Threasy.schedules }
@@ -20,6 +20,7 @@ module Threasy
20
20
  self.repeat = options[:every]
21
21
  seconds = options.fetch(:in) { repeat || 60 }
22
22
  self.at = options.fetch(:at) { Time.now + seconds }
23
+ self.times = options[:times]
23
24
  end
24
25
 
25
26
  def repeat?
@@ -47,12 +48,20 @@ module Threasy
47
48
  end
48
49
 
49
50
  def work!
51
+ return unless times_remaining?
52
+
50
53
  if once? || overdue < max_overdue
51
54
  work.enqueue job
55
+ self.times -= 1 if times
52
56
  end
57
+
53
58
  self.at = at + repeat if repeat?
54
59
  end
55
60
 
61
+ def times_remaining?
62
+ times.nil? || times > 0
63
+ end
64
+
56
65
  def remove
57
66
  schedule.remove_entry self
58
67
  end
@@ -1,3 +1,3 @@
1
1
  module Threasy
2
- VERSION = "0.3.2"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -17,6 +17,12 @@ describe Threasy::Schedule::Entry do
17
17
  entry = subject.new(job, work: work, in: hour/2, every: hour)
18
18
  Timecop.travel(Time.now + hour) { entry.work! }
19
19
  end
20
+
21
+ it "should not execute a job after the max specified times" do
22
+ entry = subject.new(job, work: work, times: 2)
23
+ expect(work).to receive(:enqueue).with(job).twice
24
+ 3.times { entry.work! }
25
+ end
20
26
  end
21
27
 
22
28
  describe "#at" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: threasy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carl Zulauf
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-20 00:00:00.000000000 Z
11
+ date: 2015-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler