threasy 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +31 -3
- data/lib/threasy/schedule/entry.rb +10 -1
- data/lib/threasy/version.rb +1 -1
- data/spec/threasy/schedule/entry_spec.rb +6 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec726270eb6e569d255112041fd86e32edba66a7
|
4
|
+
data.tar.gz: fc7b534b55f290a4f74de5559488a2496b0a19d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
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
|
data/lib/threasy/version.rb
CHANGED
@@ -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.
|
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-
|
11
|
+
date: 2015-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|