perfectsched 0.8.1 → 0.8.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/ChangeLog CHANGED
@@ -1,4 +1,13 @@
1
1
 
2
+ == 2012-07-03 version 0.8.2
3
+
4
+ * Fixed rdb_compat to raise PreemptedError and
5
+ IdempotentAlreadyFinishedError correctly
6
+ * Fixed Application module
7
+ * Added scheduled_time -> next_time and scheduled_run_time -> next_run_time
8
+ aliases to ScheduleMetadataAccessors
9
+
10
+
2
11
  == 2012-06-25 version 0.8.1
3
12
 
4
13
  * Added autoload for PerfectSched::VERSION
@@ -0,0 +1,27 @@
1
+ #
2
+ # PerfectSched
3
+ #
4
+ # Copyright (C) 2012 FURUHASHI Sadayuki
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ module PerfectSched
20
+ module Application
21
+
22
+ class Base < Runner
23
+ end
24
+
25
+ end
26
+ end
27
+
@@ -0,0 +1,46 @@
1
+ #
2
+ # PerfectSched
3
+ #
4
+ # Copyright (C) 2012 FURUHASHI Sadayuki
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ module PerfectSched
20
+ module Application
21
+
22
+ class Dispatch < Runner
23
+ # Runner interface
24
+ def initialize(task)
25
+ base = self.class.router.route(task.type)
26
+ unless base
27
+ task.retry!
28
+ raise "Unknown task type #{task.type.inspect}" # TODO error class
29
+ end
30
+ @runner = base.new(task)
31
+ super
32
+ end
33
+
34
+ attr_reader :runner
35
+
36
+ def run
37
+ @runner.run
38
+ end
39
+
40
+ # DSL interface
41
+ extend RouterDSL
42
+ end
43
+
44
+ end
45
+ end
46
+
@@ -0,0 +1,30 @@
1
+ #
2
+ # PerfectSched
3
+ #
4
+ # Copyright (C) 2012 FURUHASHI Sadayuki
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ module PerfectSched
20
+ module Application
21
+
22
+ require 'perfectqueue/application/router'
23
+
24
+ Router = PerfectQueue::Application::Router
25
+
26
+ RouterDSL = PerfectQueue::Application::RouterDSL
27
+
28
+ end
29
+ end
30
+
@@ -18,8 +18,16 @@
18
18
 
19
19
  module PerfectSched
20
20
 
21
- require 'perfectqueue/application'
22
- Application = PerfectQueue::Application
21
+ module Application
22
+ {
23
+ :Dispatch => 'application/dispatch',
24
+ :Router => 'application/router',
25
+ :RouterDSL => 'application/router',
26
+ :Base => 'application/base',
27
+ }.each_pair {|k,v|
28
+ autoload k, File.expand_path(v, File.dirname(__FILE__))
29
+ }
30
+ end
23
31
 
24
32
  end
25
33
 
@@ -54,7 +54,7 @@ module PerfectSched
54
54
 
55
55
  def init_database(options)
56
56
  sql = %[
57
- CREATE TABLE IF NOT EXISTS `test_scheds` (
57
+ CREATE TABLE IF NOT EXISTS `#{@table}` (
58
58
  id VARCHAR(256) NOT NULL,
59
59
  timeout INT NOT NULL,
60
60
  next_time INT NOT NULL,
@@ -174,8 +174,15 @@ module PerfectSched
174
174
 
175
175
  connect {
176
176
  n = @db["UPDATE `#{@table}` SET timeout=? WHERE id=? AND next_time=?;", next_run_time, row_id, scheduled_time].update
177
- if n < 0
178
- raise AlreadyFinishedError, "task time=#{Time.at(scheduled_time).utc} is already finished"
177
+ if n <= 0 # TODO fix
178
+ row = @db.fetch("SELECT id, timeout, next_time FROM `#{@table}` WHERE id=? AND next_time=? LIMIT 1", row_id, scheduled_time).first
179
+ if row == nil
180
+ raise PreemptedError, "task key=#{key} does not exist or preempted."
181
+ elsif row[:timeout] == next_run_time
182
+ # ok
183
+ else
184
+ raise PreemptedError, "task time=#{Time.at(scheduled_time).utc} is preempted"
185
+ end
179
186
  end
180
187
  }
181
188
  end
@@ -188,7 +195,7 @@ module PerfectSched
188
195
 
189
196
  connect {
190
197
  n = @db["UPDATE `#{@table}` SET timeout=?, next_time=? WHERE id=? AND next_time=?;", next_run_time, next_time, row_id, scheduled_time].update
191
- if n < 0
198
+ if n <= 0
192
199
  raise IdempotentAlreadyFinishedError, "task time=#{Time.at(scheduled_time).utc} is already finished"
193
200
  end
194
201
  }
@@ -49,6 +49,10 @@ module PerfectSched
49
49
  @attributes[:next_run_time]
50
50
  end
51
51
 
52
+ alias scheduled_time next_time
53
+
54
+ alias scheduled_run_time next_run_time
55
+
52
56
  def message
53
57
  @attributes[:message]
54
58
  end
@@ -1,3 +1,3 @@
1
1
  module PerfectSched
2
- VERSION = "0.8.1"
2
+ VERSION = "0.8.2"
3
3
  end
@@ -153,8 +153,6 @@ module PerfectSched
153
153
  sig.trap :USR2 do
154
154
  logrotated
155
155
  end
156
-
157
- trap :CHLD, "SIG_IGN"
158
156
  end
159
157
  end
160
158
  end
data/perfectsched.gemspec CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |gem|
19
19
  gem.add_dependency "cron-spec", [">= 0.1.2", "<= 0.1.2"]
20
20
  gem.add_dependency "sequel", "~> 3.26.0"
21
21
  gem.add_dependency "tzinfo", "~> 0.3.29"
22
- gem.add_dependency "perfectqueue", "~> 0.8.0"
22
+ gem.add_dependency "perfectqueue", "~> 0.8.3"
23
23
  gem.add_development_dependency "rake", "~> 0.9.2"
24
24
  gem.add_development_dependency "rspec", "~> 2.10.0"
25
25
  gem.add_development_dependency "simplecov", "~> 0.5.4"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: perfectsched
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.8.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-25 00:00:00.000000000Z
12
+ date: 2012-07-04 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cron-spec
16
- requirement: &70165887081720 !ruby/object:Gem::Requirement
16
+ requirement: &70202080349100 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -24,10 +24,10 @@ dependencies:
24
24
  version: 0.1.2
25
25
  type: :runtime
26
26
  prerelease: false
27
- version_requirements: *70165887081720
27
+ version_requirements: *70202080349100
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: sequel
30
- requirement: &70165887079760 !ruby/object:Gem::Requirement
30
+ requirement: &70202080348340 !ruby/object:Gem::Requirement
31
31
  none: false
32
32
  requirements:
33
33
  - - ~>
@@ -35,10 +35,10 @@ dependencies:
35
35
  version: 3.26.0
36
36
  type: :runtime
37
37
  prerelease: false
38
- version_requirements: *70165887079760
38
+ version_requirements: *70202080348340
39
39
  - !ruby/object:Gem::Dependency
40
40
  name: tzinfo
41
- requirement: &70165887078760 !ruby/object:Gem::Requirement
41
+ requirement: &70202080347880 !ruby/object:Gem::Requirement
42
42
  none: false
43
43
  requirements:
44
44
  - - ~>
@@ -46,21 +46,21 @@ dependencies:
46
46
  version: 0.3.29
47
47
  type: :runtime
48
48
  prerelease: false
49
- version_requirements: *70165887078760
49
+ version_requirements: *70202080347880
50
50
  - !ruby/object:Gem::Dependency
51
51
  name: perfectqueue
52
- requirement: &70165887077360 !ruby/object:Gem::Requirement
52
+ requirement: &70202080347420 !ruby/object:Gem::Requirement
53
53
  none: false
54
54
  requirements:
55
55
  - - ~>
56
56
  - !ruby/object:Gem::Version
57
- version: 0.8.0
57
+ version: 0.8.3
58
58
  type: :runtime
59
59
  prerelease: false
60
- version_requirements: *70165887077360
60
+ version_requirements: *70202080347420
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: rake
63
- requirement: &70165887076440 !ruby/object:Gem::Requirement
63
+ requirement: &70202080346960 !ruby/object:Gem::Requirement
64
64
  none: false
65
65
  requirements:
66
66
  - - ~>
@@ -68,10 +68,10 @@ dependencies:
68
68
  version: 0.9.2
69
69
  type: :development
70
70
  prerelease: false
71
- version_requirements: *70165887076440
71
+ version_requirements: *70202080346960
72
72
  - !ruby/object:Gem::Dependency
73
73
  name: rspec
74
- requirement: &70165887075580 !ruby/object:Gem::Requirement
74
+ requirement: &70202079928960 !ruby/object:Gem::Requirement
75
75
  none: false
76
76
  requirements:
77
77
  - - ~>
@@ -79,10 +79,10 @@ dependencies:
79
79
  version: 2.10.0
80
80
  type: :development
81
81
  prerelease: false
82
- version_requirements: *70165887075580
82
+ version_requirements: *70202079928960
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: simplecov
85
- requirement: &70165887074140 !ruby/object:Gem::Requirement
85
+ requirement: &70202079928500 !ruby/object:Gem::Requirement
86
86
  none: false
87
87
  requirements:
88
88
  - - ~>
@@ -90,10 +90,10 @@ dependencies:
90
90
  version: 0.5.4
91
91
  type: :development
92
92
  prerelease: false
93
- version_requirements: *70165887074140
93
+ version_requirements: *70202079928500
94
94
  - !ruby/object:Gem::Dependency
95
95
  name: sqlite3
96
- requirement: &70165887069320 !ruby/object:Gem::Requirement
96
+ requirement: &70202079928040 !ruby/object:Gem::Requirement
97
97
  none: false
98
98
  requirements:
99
99
  - - ~>
@@ -101,7 +101,7 @@ dependencies:
101
101
  version: 1.3.3
102
102
  type: :development
103
103
  prerelease: false
104
- version_requirements: *70165887069320
104
+ version_requirements: *70202079928040
105
105
  description: Highly available distributed cron built on RDBMS
106
106
  email: frsyuki@gmail.com
107
107
  executables:
@@ -117,6 +117,9 @@ files:
117
117
  - bin/perfectsched
118
118
  - lib/perfectsched.rb
119
119
  - lib/perfectsched/application.rb
120
+ - lib/perfectsched/application/base.rb
121
+ - lib/perfectsched/application/dispatch.rb
122
+ - lib/perfectsched/application/router.rb
120
123
  - lib/perfectsched/backend.rb
121
124
  - lib/perfectsched/backend/rdb_compat.rb
122
125
  - lib/perfectsched/blocking_flag.rb