clockwork 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +50 -0
- data/VERSION +1 -1
- data/bin/clockwork +1 -2
- data/lib/clockwork.rb +2 -2
- data/test/clockwork_test.rb +38 -16
- metadata +6 -26
data/README.md
CHANGED
@@ -35,6 +35,31 @@ Run it with the clockwork binary:
|
|
35
35
|
Starting clock for 4 events: [ frequent.job less.frequent.job hourly.job midnight.job ]
|
36
36
|
Triggering frequent.job
|
37
37
|
|
38
|
+
If you would not like to taint the namespace with `include Clockwork`, you can use
|
39
|
+
it as the module (thanks to [hoverlover](https://github.com/hoverlover/clockwork/)).
|
40
|
+
|
41
|
+
require 'clockwork'
|
42
|
+
|
43
|
+
module Clockwork
|
44
|
+
handler do |job|
|
45
|
+
puts "Running #{job}"
|
46
|
+
end
|
47
|
+
|
48
|
+
every(10.seconds, 'frequent.job')
|
49
|
+
every(3.minutes, 'less.frequent.job')
|
50
|
+
every(1.hour, 'hourly.job')
|
51
|
+
|
52
|
+
every(1.day, 'midnight.job', :at => '00:00')
|
53
|
+
end
|
54
|
+
|
55
|
+
Quickstart for Heroku
|
56
|
+
---------------------
|
57
|
+
|
58
|
+
Clockwork fits well with heroku's cedar stack.
|
59
|
+
|
60
|
+
Consider to use [clockwork-init.sh](https://gist.github.com/1312172) to create
|
61
|
+
a new project for heroku.
|
62
|
+
|
38
63
|
Use with queueing
|
39
64
|
-----------------
|
40
65
|
|
@@ -70,6 +95,31 @@ enqueue methods. For example, with DJ/Rails:
|
|
70
95
|
every(1.hour, 'feeds.refresh') { Feed.send_later(:refresh) }
|
71
96
|
every(1.day, 'reminders.send', :at => '01:30') { Reminder.send_later(:send_reminders) }
|
72
97
|
|
98
|
+
Parameters
|
99
|
+
----------
|
100
|
+
|
101
|
+
### :at
|
102
|
+
|
103
|
+
`:at` parameter the hour and minute specifies when the event occur.
|
104
|
+
|
105
|
+
The simplest example:
|
106
|
+
|
107
|
+
every(1.day, 'reminders.send', :at => '01:30')
|
108
|
+
|
109
|
+
You can omit 0 of the hour:
|
110
|
+
|
111
|
+
every(1.day, 'reminders.send', :at => '1:30')
|
112
|
+
|
113
|
+
The wildcard for hour is supported:
|
114
|
+
|
115
|
+
every(1.hour, 'reminders.send', :at => '**:30')
|
116
|
+
|
117
|
+
You can set more than one timing:
|
118
|
+
|
119
|
+
every(1.hour, 'reminders.send', :at => ['12:00', '18:00'])
|
120
|
+
# send reminders at noon and evening
|
121
|
+
|
122
|
+
|
73
123
|
Anatomy of a clock file
|
74
124
|
-----------------------
|
75
125
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.2
|
data/bin/clockwork
CHANGED
@@ -3,7 +3,6 @@
|
|
3
3
|
STDERR.sync = STDOUT.sync = true
|
4
4
|
|
5
5
|
require File.expand_path('../../lib/clockwork', __FILE__)
|
6
|
-
include Clockwork
|
7
6
|
|
8
7
|
usage = "clockwork <clock.rb>"
|
9
8
|
file = ARGV.shift or abort usage
|
@@ -17,4 +16,4 @@ trap('INT') do
|
|
17
16
|
exit
|
18
17
|
end
|
19
18
|
|
20
|
-
run
|
19
|
+
Clockwork::run
|
data/lib/clockwork.rb
CHANGED
@@ -49,12 +49,12 @@ module Clockwork
|
|
49
49
|
def parse_at(at)
|
50
50
|
return unless at
|
51
51
|
case at
|
52
|
-
when /^(\d
|
52
|
+
when /^(\d{1,2}):(\d\d)$/
|
53
53
|
hour = $1.to_i
|
54
54
|
min = $2.to_i
|
55
55
|
raise FailedToParse, at if hour >= 24 || min >= 60
|
56
56
|
[hour, min]
|
57
|
-
when
|
57
|
+
when /^\*{1,2}:(\d\d)$/
|
58
58
|
min = $1.to_i
|
59
59
|
raise FailedToParse, at if min >= 60
|
60
60
|
[nil, min]
|
data/test/clockwork_test.rb
CHANGED
@@ -16,10 +16,16 @@ class ClockworkTest < Test::Unit::TestCase
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def assert_will_run(t)
|
19
|
+
if t.is_a? String
|
20
|
+
t = Time.parse(t)
|
21
|
+
end
|
19
22
|
assert_equal 1, Clockwork.tick(t).size
|
20
23
|
end
|
21
24
|
|
22
25
|
def assert_wont_run(t)
|
26
|
+
if t.is_a? String
|
27
|
+
t = Time.parse(t)
|
28
|
+
end
|
23
29
|
assert_equal 0, Clockwork.tick(t).size
|
24
30
|
end
|
25
31
|
|
@@ -50,33 +56,49 @@ class ClockworkTest < Test::Unit::TestCase
|
|
50
56
|
test "once a day at 16:20" do
|
51
57
|
Clockwork.every(1.day, 'myjob', :at => '16:20')
|
52
58
|
|
53
|
-
assert_wont_run
|
54
|
-
assert_will_run
|
55
|
-
assert_wont_run
|
56
|
-
assert_wont_run
|
57
|
-
assert_will_run
|
59
|
+
assert_wont_run 'jan 1 2010 16:19:59'
|
60
|
+
assert_will_run 'jan 1 2010 16:20:00'
|
61
|
+
assert_wont_run 'jan 1 2010 16:20:01'
|
62
|
+
assert_wont_run 'jan 2 2010 16:19:59'
|
63
|
+
assert_will_run 'jan 2 2010 16:20:00'
|
64
|
+
end
|
65
|
+
|
66
|
+
test ":at also accepts 8:20" do
|
67
|
+
Clockwork.every(1.hour, 'myjob', :at => '8:20')
|
68
|
+
|
69
|
+
assert_wont_run 'jan 1 2010 08:19:59'
|
70
|
+
assert_will_run 'jan 1 2010 08:20:00'
|
71
|
+
assert_wont_run 'jan 1 2010 08:20:01'
|
58
72
|
end
|
59
73
|
|
60
74
|
test "twice a day at 16:20 and 18:10" do
|
61
75
|
Clockwork.every(1.day, 'myjob', :at => ['16:20', '18:10'])
|
62
76
|
|
63
|
-
assert_wont_run
|
64
|
-
assert_will_run
|
65
|
-
assert_wont_run
|
77
|
+
assert_wont_run 'jan 1 2010 16:19:59'
|
78
|
+
assert_will_run 'jan 1 2010 16:20:00'
|
79
|
+
assert_wont_run 'jan 1 2010 16:20:01'
|
66
80
|
|
67
|
-
assert_wont_run
|
68
|
-
assert_will_run
|
69
|
-
assert_wont_run
|
81
|
+
assert_wont_run 'jan 1 2010 18:09:59'
|
82
|
+
assert_will_run 'jan 1 2010 18:10:00'
|
83
|
+
assert_wont_run 'jan 1 2010 18:10:01'
|
70
84
|
end
|
71
85
|
|
72
86
|
test "once an hour at **:20" do
|
73
87
|
Clockwork.every(1.hour, 'myjob', :at => '**:20')
|
74
88
|
|
75
|
-
assert_wont_run
|
76
|
-
assert_will_run
|
77
|
-
assert_wont_run
|
78
|
-
assert_wont_run
|
79
|
-
assert_will_run
|
89
|
+
assert_wont_run 'jan 1 2010 15:19:59'
|
90
|
+
assert_will_run 'jan 1 2010 15:20:00'
|
91
|
+
assert_wont_run 'jan 1 2010 15:20:01'
|
92
|
+
assert_wont_run 'jan 2 2010 16:19:59'
|
93
|
+
assert_will_run 'jan 2 2010 16:20:00'
|
94
|
+
end
|
95
|
+
|
96
|
+
test ":at also accepts *:20" do
|
97
|
+
Clockwork.every(1.hour, 'myjob', :at => '*:20')
|
98
|
+
|
99
|
+
assert_wont_run 'jan 1 2010 15:19:59'
|
100
|
+
assert_will_run 'jan 1 2010 15:20:00'
|
101
|
+
assert_wont_run 'jan 1 2010 15:20:01'
|
80
102
|
end
|
81
103
|
|
82
104
|
test "aborts when no handler defined" do
|
metadata
CHANGED
@@ -1,13 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clockwork
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 17
|
5
4
|
prerelease:
|
6
|
-
|
7
|
-
- 0
|
8
|
-
- 3
|
9
|
-
- 1
|
10
|
-
version: 0.3.1
|
5
|
+
version: 0.3.2
|
11
6
|
platform: ruby
|
12
7
|
authors:
|
13
8
|
- Adam Wiggins
|
@@ -15,50 +10,41 @@ autorequire:
|
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
12
|
|
18
|
-
date: 2011-
|
13
|
+
date: 2011-11-11 00:00:00 +09:00
|
19
14
|
default_executable: clockwork
|
20
15
|
dependencies:
|
21
16
|
- !ruby/object:Gem::Dependency
|
22
17
|
name: jeweler
|
23
|
-
prerelease: false
|
24
18
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
19
|
none: false
|
26
20
|
requirements:
|
27
21
|
- - ">="
|
28
22
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 3
|
30
|
-
segments:
|
31
|
-
- 0
|
32
23
|
version: "0"
|
33
24
|
type: :development
|
25
|
+
prerelease: false
|
34
26
|
version_requirements: *id001
|
35
27
|
- !ruby/object:Gem::Dependency
|
36
28
|
name: contest
|
37
|
-
prerelease: false
|
38
29
|
requirement: &id002 !ruby/object:Gem::Requirement
|
39
30
|
none: false
|
40
31
|
requirements:
|
41
32
|
- - ">="
|
42
33
|
- !ruby/object:Gem::Version
|
43
|
-
hash: 3
|
44
|
-
segments:
|
45
|
-
- 0
|
46
34
|
version: "0"
|
47
35
|
type: :development
|
36
|
+
prerelease: false
|
48
37
|
version_requirements: *id002
|
49
38
|
- !ruby/object:Gem::Dependency
|
50
39
|
name: mocha
|
51
|
-
prerelease: false
|
52
40
|
requirement: &id003 !ruby/object:Gem::Requirement
|
53
41
|
none: false
|
54
42
|
requirements:
|
55
43
|
- - ">="
|
56
44
|
- !ruby/object:Gem::Version
|
57
|
-
hash: 3
|
58
|
-
segments:
|
59
|
-
- 0
|
60
45
|
version: "0"
|
61
46
|
type: :development
|
47
|
+
prerelease: false
|
62
48
|
version_requirements: *id003
|
63
49
|
description: A scheduler process to replace cron, using a more flexible Ruby syntax running as a single long-running process. Inspired by rufus-scheduler and resque-scheduler.
|
64
50
|
email: adam@heroku.com
|
@@ -91,23 +77,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
91
77
|
requirements:
|
92
78
|
- - ">="
|
93
79
|
- !ruby/object:Gem::Version
|
94
|
-
hash: 3
|
95
|
-
segments:
|
96
|
-
- 0
|
97
80
|
version: "0"
|
98
81
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
82
|
none: false
|
100
83
|
requirements:
|
101
84
|
- - ">="
|
102
85
|
- !ruby/object:Gem::Version
|
103
|
-
hash: 3
|
104
|
-
segments:
|
105
|
-
- 0
|
106
86
|
version: "0"
|
107
87
|
requirements: []
|
108
88
|
|
109
89
|
rubyforge_project: clockwork
|
110
|
-
rubygems_version: 1.
|
90
|
+
rubygems_version: 1.5.0
|
111
91
|
signing_key:
|
112
92
|
specification_version: 3
|
113
93
|
summary: A scheduler process to replace cron.
|