sidetiq 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +11 -0
- data/examples/simple.rb +4 -0
- data/lib/sidetiq.rb +4 -0
- data/lib/sidetiq/clock.rb +68 -3
- data/lib/sidetiq/config.rb +12 -0
- data/lib/sidetiq/schedulable.rb +13 -2
- data/lib/sidetiq/schedule.rb +1 -0
- data/lib/sidetiq/version.rb +8 -1
- data/lib/sidetiq/web.rb +0 -1
- data/sidetiq.gemspec +2 -2
- metadata +9 -9
data/README.md
CHANGED
@@ -2,6 +2,7 @@ Sidetiq
|
|
2
2
|
=======
|
3
3
|
|
4
4
|
[![Build Status](https://travis-ci.org/tobiassvn/sidetiq.png)](https://travis-ci.org/tobiassvn/sidetiq)
|
5
|
+
[![Dependency Status](https://gemnasium.com/tobiassvn/sidetiq.png)](https://gemnasium.com/tobiassvn/sidetiq)
|
5
6
|
|
6
7
|
Recurring jobs for [Sidekiq](http://mperham.github.com/sidekiq/).
|
7
8
|
|
@@ -118,6 +119,16 @@ loaded by default, so it will have to be required manually:
|
|
118
119
|
require 'sidetiq/web'
|
119
120
|
```
|
120
121
|
|
122
|
+
### NOTES
|
123
|
+
|
124
|
+
By default Sidekiq uses a 15 second polling interval to check if scheduled
|
125
|
+
jobs are due. If a recurring job has to run more often than that you should
|
126
|
+
lower this value.
|
127
|
+
|
128
|
+
```ruby
|
129
|
+
Sidekiq.options[:poll_interval] = 1
|
130
|
+
```
|
131
|
+
|
121
132
|
### SCREENSHOT
|
122
133
|
|
123
134
|
![Screenshot](http://f.cl.ly/items/1P2u1v091F3V1n381g2I/Screen%20Shot%202013-02-01%20at%2012.16.17.png)
|
data/examples/simple.rb
CHANGED
data/lib/sidetiq.rb
CHANGED
data/lib/sidetiq/clock.rb
CHANGED
@@ -6,27 +6,52 @@ module Sidetiq
|
|
6
6
|
config.utc = false
|
7
7
|
end
|
8
8
|
|
9
|
+
# Public: The Sidetiq clock.
|
9
10
|
class Clock
|
10
11
|
include Singleton
|
11
12
|
include MonitorMixin
|
12
13
|
|
14
|
+
# Public: Start time offset from epoch used for calculating run
|
15
|
+
# times in the Sidetiq schedules.
|
13
16
|
START_TIME = Sidetiq.config.utc ? Time.utc(2010, 1, 1) : Time.local(2010, 1, 1)
|
14
17
|
|
15
|
-
|
18
|
+
# Public: Returns a hash of Sidetiq::Schedule instances.
|
19
|
+
attr_reader :schedules
|
16
20
|
|
17
|
-
|
21
|
+
# Public: Returns the clock thread.
|
22
|
+
attr_reader :thread
|
23
|
+
|
24
|
+
def self.method_missing(meth, *args, &block) # :nodoc:
|
18
25
|
instance.__send__(meth, *args, &block)
|
19
26
|
end
|
20
27
|
|
21
|
-
def initialize
|
28
|
+
def initialize # :nodoc:
|
22
29
|
super
|
23
30
|
@schedules = {}
|
24
31
|
end
|
25
32
|
|
33
|
+
# Public: Get the schedule for `worker`.
|
34
|
+
#
|
35
|
+
# worker - A Sidekiq::Worker class
|
36
|
+
#
|
37
|
+
# Examples
|
38
|
+
#
|
39
|
+
# schedule_for(MyWorker)
|
40
|
+
# # => Sidetiq::Schedule
|
41
|
+
#
|
42
|
+
# Returns a Sidetiq::Schedule instances.
|
26
43
|
def schedule_for(worker)
|
27
44
|
schedules[worker] ||= Sidetiq::Schedule.new(START_TIME)
|
28
45
|
end
|
29
46
|
|
47
|
+
# Public: Issue a single clock tick.
|
48
|
+
#
|
49
|
+
# Examples
|
50
|
+
#
|
51
|
+
# tick
|
52
|
+
# # => Hash of Sidetiq::Schedule objects
|
53
|
+
#
|
54
|
+
# Returns a hash of Sidetiq::Schedule instances.
|
30
55
|
def tick
|
31
56
|
@tick = gettime
|
32
57
|
synchronize do
|
@@ -38,10 +63,29 @@ module Sidetiq
|
|
38
63
|
end
|
39
64
|
end
|
40
65
|
|
66
|
+
# Public: Returns the current time used by the clock.
|
67
|
+
#
|
68
|
+
# Sidetiq::Clock uses `clock_gettime()` on UNIX systems and
|
69
|
+
# `mach_absolute_time()` on Mac OS X.
|
70
|
+
#
|
71
|
+
# Examples
|
72
|
+
#
|
73
|
+
# gettime
|
74
|
+
# # => 2013-02-04 12:00:45 +0000
|
75
|
+
#
|
76
|
+
# Returns a Time instance.
|
41
77
|
def gettime
|
42
78
|
Sidetiq.config.utc ? clock_gettime.utc : clock_gettime
|
43
79
|
end
|
44
80
|
|
81
|
+
# Public: Starts the clock unless it is already running.
|
82
|
+
#
|
83
|
+
# Examples
|
84
|
+
#
|
85
|
+
# start!
|
86
|
+
# # => Thread
|
87
|
+
#
|
88
|
+
# Returns the Thread instance of the clock thread.
|
45
89
|
def start!
|
46
90
|
return if ticking?
|
47
91
|
|
@@ -49,8 +93,17 @@ module Sidetiq
|
|
49
93
|
@thread = Thread.start { clock { tick } }
|
50
94
|
@thread.abort_on_exception = true
|
51
95
|
@thread.priority = Sidetiq.config.resolution
|
96
|
+
@thread
|
52
97
|
end
|
53
98
|
|
99
|
+
# Public: Stops the clock if it is running.
|
100
|
+
#
|
101
|
+
# Examples
|
102
|
+
#
|
103
|
+
# stop!
|
104
|
+
# # => nil
|
105
|
+
#
|
106
|
+
# Returns nil.
|
54
107
|
def stop!
|
55
108
|
if ticking?
|
56
109
|
@thread.kill
|
@@ -58,6 +111,18 @@ module Sidetiq
|
|
58
111
|
end
|
59
112
|
end
|
60
113
|
|
114
|
+
# Public: Returns the status of the clock.
|
115
|
+
#
|
116
|
+
# Examples
|
117
|
+
#
|
118
|
+
# ticking?
|
119
|
+
# # => false
|
120
|
+
#
|
121
|
+
# start!
|
122
|
+
# ticking?
|
123
|
+
# # => true
|
124
|
+
#
|
125
|
+
# Returns true or false.
|
61
126
|
def ticking?
|
62
127
|
@thread && @thread.alive?
|
63
128
|
end
|
data/lib/sidetiq/config.rb
CHANGED
@@ -1,11 +1,23 @@
|
|
1
1
|
module Sidetiq
|
2
2
|
class << self
|
3
|
+
# Public: Sets the configuration used by Sidetiq.
|
3
4
|
attr_writer :config
|
4
5
|
|
6
|
+
# Public: Configuration wrapper for block configurations.
|
7
|
+
#
|
8
|
+
# Examples
|
9
|
+
#
|
10
|
+
# Sidetiq.configure do |config|
|
11
|
+
# config.resolution = 0.2
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# Yields the configuration OpenStruct currently set.
|
15
|
+
# Returns nothing.
|
5
16
|
def configure
|
6
17
|
yield config
|
7
18
|
end
|
8
19
|
|
20
|
+
# Public: Returns the current configuration used by Sidetiq.
|
9
21
|
def config
|
10
22
|
@config ||= OpenStruct.new
|
11
23
|
end
|
data/lib/sidetiq/schedulable.rb
CHANGED
@@ -1,7 +1,18 @@
|
|
1
1
|
module Sidetiq
|
2
|
+
# Public: Mixin for Sidekiq::Worker classes.
|
3
|
+
#
|
4
|
+
# Examples
|
5
|
+
#
|
6
|
+
# class MyWorker
|
7
|
+
# include Sidekiq::Worker
|
8
|
+
# include Sidetiq::Schedulable
|
9
|
+
#
|
10
|
+
# # Daily at midnight
|
11
|
+
# tiq { daily }
|
12
|
+
# end
|
2
13
|
module Schedulable
|
3
14
|
module ClassMethods
|
4
|
-
def tiq(&block)
|
15
|
+
def tiq(&block) # :nodoc:
|
5
16
|
clock = Sidetiq::Clock.instance
|
6
17
|
clock.synchronize do
|
7
18
|
clock.schedule_for(self).instance_eval(&block)
|
@@ -9,7 +20,7 @@ module Sidetiq
|
|
9
20
|
end
|
10
21
|
end
|
11
22
|
|
12
|
-
def self.included(klass)
|
23
|
+
def self.included(klass) # :nodoc:
|
13
24
|
klass.extend(Sidetiq::Schedulable::ClassMethods)
|
14
25
|
end
|
15
26
|
end
|
data/lib/sidetiq/schedule.rb
CHANGED
data/lib/sidetiq/version.rb
CHANGED
@@ -1,9 +1,16 @@
|
|
1
1
|
module Sidetiq
|
2
|
+
# Public: Sidetiq version namespace.
|
2
3
|
module VERSION
|
4
|
+
# Public: Sidetiq major version number.
|
3
5
|
MAJOR = 0
|
6
|
+
|
7
|
+
# Public: Sidetiq minor version number.
|
4
8
|
MINOR = 1
|
5
|
-
PATCH = 2
|
6
9
|
|
10
|
+
# Public: Sidetiq patch level.
|
11
|
+
PATCH = 3
|
12
|
+
|
13
|
+
# Public: String representation of the current Sidetiq version.
|
7
14
|
STRING = [MAJOR, MINOR, PATCH].compact.join('.')
|
8
15
|
end
|
9
16
|
end
|
data/lib/sidetiq/web.rb
CHANGED
data/sidetiq.gemspec
CHANGED
@@ -19,6 +19,6 @@ Gem::Specification.new do |gem|
|
|
19
19
|
gem.require_paths = ["lib"]
|
20
20
|
gem.extensions = ['ext/sidetiq_ext/extconf.rb']
|
21
21
|
|
22
|
-
gem.add_dependency 'sidekiq'
|
23
|
-
gem.add_dependency 'ice_cube'
|
22
|
+
gem.add_dependency 'sidekiq', '~> 2.7.0'
|
23
|
+
gem.add_dependency 'ice_cube', '~> 0.9.3'
|
24
24
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: sidetiq
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Tobias Svensson
|
@@ -14,34 +14,34 @@ dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
version_requirements: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 2.7.0
|
20
20
|
none: false
|
21
21
|
name: sidekiq
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
requirement: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
|
-
- -
|
26
|
+
- - ~>
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
-
version:
|
28
|
+
version: 2.7.0
|
29
29
|
none: false
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
version_requirements: !ruby/object:Gem::Requirement
|
32
32
|
requirements:
|
33
|
-
- -
|
33
|
+
- - ~>
|
34
34
|
- !ruby/object:Gem::Version
|
35
|
-
version:
|
35
|
+
version: 0.9.3
|
36
36
|
none: false
|
37
37
|
name: ice_cube
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
requirement: !ruby/object:Gem::Requirement
|
41
41
|
requirements:
|
42
|
-
- -
|
42
|
+
- - ~>
|
43
43
|
- !ruby/object:Gem::Version
|
44
|
-
version:
|
44
|
+
version: 0.9.3
|
45
45
|
none: false
|
46
46
|
description: High-resolution job scheduler for Sidekiq
|
47
47
|
email:
|