perfectsched 0.8.6 → 0.8.7

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,4 +1,8 @@
1
1
 
2
+ == 2014-04-23 version 0.8.7
3
+
4
+ * Reverted commits for 0.8.5 and applied commits for 0.8.6, in particular, added commit for MySQL's SSL support
5
+
2
6
  == 2014-04-21 version 0.8.6
3
7
 
4
8
  * Added SSL support for MySQL backend
data/lib/perfectsched.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # PerfectSched
3
3
  #
4
- # Copyright (C) 2012-2013 Sadayuki Furuhashi
4
+ # Copyright (C) 2012 FURUHASHI Sadayuki
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # PerfectSched
3
3
  #
4
- # Copyright (C) 2012-2013 Sadayuki Furuhashi
4
+ # Copyright (C) 2012 FURUHASHI Sadayuki
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # PerfectSched
3
3
  #
4
- # Copyright (C) 2012-2013 Sadayuki Furuhashi
4
+ # Copyright (C) 2012 FURUHASHI Sadayuki
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # PerfectSched
3
3
  #
4
- # Copyright (C) 2012-2013 Sadayuki Furuhashi
4
+ # Copyright (C) 2012 FURUHASHI Sadayuki
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -40,7 +40,7 @@ module PerfectSched
40
40
  begin
41
41
  m = method(type)
42
42
  rescue NameError
43
- raise UndefinedDecisionError, "Undefined decision #{type} options=#{opts.inspect}"
43
+ raise UndefinedDecisionError, "Undefined decision #{type} options=#{opt.inspect}"
44
44
  end
45
45
  m.call(opts)
46
46
  end
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # PerfectSched
3
3
  #
4
- # Copyright (C) 2012-2013 Sadayuki Furuhashi
4
+ # Copyright (C) 2012 FURUHASHI Sadayuki
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -22,10 +22,10 @@ module PerfectSched
22
22
  class Dispatch < Runner
23
23
  # Runner interface
24
24
  def initialize(task)
25
- base = self.class.router.route(task.key)
25
+ base = self.class.router.route(task.type)
26
26
  unless base
27
- task.retry! # TODO or release?
28
- raise "Unknown task key #{task.key.inspect}" # TODO error class
27
+ task.retry!
28
+ raise "Unknown task type #{task.type.inspect}" # TODO error class
29
29
  end
30
30
  @runner = base.new(task)
31
31
  super
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # PerfectSched
3
3
  #
4
- # Copyright (C) 2012-2013 Sadayuki Furuhashi
4
+ # Copyright (C) 2012 FURUHASHI Sadayuki
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # PerfectSched
3
3
  #
4
- # Copyright (C) 2012-2013 Sadayuki Furuhashi
4
+ # Copyright (C) 2012 FURUHASHI Sadayuki
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # PerfectSched
3
3
  #
4
- # Copyright (C) 2012-2013 Sadayuki Furuhashi
4
+ # Copyright (C) 2012 FURUHASHI Sadayuki
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -21,7 +21,7 @@ module PerfectSched
21
21
  class RDBCompatBackend
22
22
  include BackendHelper
23
23
 
24
- class Token < Struct.new(:row_id, :scheduled_time, :cron, :delay, :timezone, :data)
24
+ class Token < Struct.new(:row_id, :scheduled_time, :cron, :delay, :timezone)
25
25
  end
26
26
 
27
27
  def initialize(client, config)
@@ -76,13 +76,13 @@ module PerfectSched
76
76
  def init_database(options)
77
77
  sql = %[
78
78
  CREATE TABLE IF NOT EXISTS `#{@table}` (
79
- id VARCHAR(256) character set ascii NOT NULL,
79
+ id VARCHAR(256) NOT NULL,
80
80
  timeout INT NOT NULL,
81
81
  next_time INT NOT NULL,
82
- cron VARCHAR(128) character set ascii NOT NULL,
82
+ cron VARCHAR(128) NOT NULL,
83
83
  delay INT NOT NULL,
84
- timezone VARCHAR(256) character set ascii NULL,
85
84
  data BLOB NOT NULL,
85
+ timezone VARCHAR(256) NULL,
86
86
  PRIMARY KEY (id)
87
87
  );]
88
88
  connect {
@@ -92,7 +92,7 @@ module PerfectSched
92
92
 
93
93
  def get_schedule_metadata(key, options={})
94
94
  connect {
95
- row = @db.fetch("SELECT id, timeout, next_time, cron, delay, timezone, data FROM `#{@table}` WHERE id=? LIMIT 1", key).first
95
+ row = @db.fetch("SELECT id, timeout, next_time, cron, delay, data, timezone FROM `#{@table}` WHERE id=? LIMIT 1", key).first
96
96
  unless row
97
97
  raise NotFoundError, "schedule key=#{key} does not exist"
98
98
  end
@@ -103,7 +103,7 @@ module PerfectSched
103
103
 
104
104
  def list(options, &block)
105
105
  connect {
106
- @db.fetch("SELECT id, timeout, next_time, cron, delay, timezone, data FROM `#{@table}` ORDER BY timeout ASC") {|row|
106
+ @db.fetch("SELECT id, timeout, next_time, cron, delay, data, timezone FROM `#{@table}` ORDER BY timeout ASC") {|row|
107
107
  attributes = create_attributes(row)
108
108
  sched = ScheduleWithMetadata.new(@client, row[:id], attributes)
109
109
  yield sched
@@ -111,11 +111,12 @@ module PerfectSched
111
111
  }
112
112
  end
113
113
 
114
- def add(key, cron, delay, timezone, next_time, next_run_time, options)
115
- data = options[:data] || {}
114
+ def add(key, type, cron, delay, timezone, data, next_time, next_run_time, options)
115
+ data = data ? data.dup : {}
116
+ data['type'] = type
116
117
  connect {
117
118
  begin
118
- n = @db["INSERT INTO `#{@table}` (id, timeout, next_time, cron, delay, timezone, data) VALUES (?, ?, ?, ?, ?, ?, ?)", key, next_run_time, next_time, cron, delay, timezone, data.to_json].insert
119
+ n = @db["INSERT INTO `#{@table}` (id, timeout, next_time, cron, delay, data, timezone) VALUES (?, ?, ?, ?, ?, ?, ?);", key, next_run_time, next_time, cron, delay, data.to_json, timezone].insert
119
120
  return Schedule.new(@client, key)
120
121
  rescue Sequel::DatabaseError
121
122
  raise IdempotentAlreadyExistsError, "schedule key=#{key} already exists"
@@ -125,7 +126,7 @@ module PerfectSched
125
126
 
126
127
  def delete(key, options)
127
128
  connect {
128
- n = @db["DELETE FROM `#{@table}` WHERE id=?", key].delete
129
+ n = @db["DELETE FROM `#{@table}` WHERE id=?;", key].delete
129
130
  if n <= 0
130
131
  raise IdempotentNotFoundError, "schedule key=#{key} does no exist"
131
132
  end
@@ -136,17 +137,12 @@ module PerfectSched
136
137
  ks = []
137
138
  vs = []
138
139
  [:cron, :delay, :timezone].each {|k|
140
+ # TODO type and data are not supported
139
141
  if v = options[k]
140
142
  ks << k
141
143
  vs << v
142
144
  end
143
145
  }
144
- [:data].each {|k|
145
- if v = options[k]
146
- ks << k
147
- vs << v.to_json
148
- end
149
- }
150
146
  return nil if ks.empty?
151
147
 
152
148
  sql = "UPDATE `#{@table}` SET "
@@ -167,29 +163,17 @@ module PerfectSched
167
163
  def acquire(alive_time, max_acquire, options)
168
164
  now = (options[:now] || Time.now).to_i
169
165
  next_timeout = now + alive_time
170
- only_keys = options[:only_keys]
171
-
172
- select_sql = "SELECT id, timeout, next_time, cron, delay, timezone, data FROM `#{@table}` WHERE timeout <= ?"
173
- select_params = [select_sql, now]
174
- if only_keys
175
- select_sql << " AND id IN ("
176
- select_sql << only_keys.map {|k|
177
- select_params << k
178
- '?'
179
- }.join(', ')
180
- select_sql << ')'
181
- end
182
- select_sql << " ORDER BY timeout ASC LIMIT #{MAX_SELECT_ROW}"
183
166
 
184
167
  connect {
185
168
  while true
186
169
  rows = 0
187
- @db.fetch(*select_params) {|row|
188
- n = @db["UPDATE `#{@table}` SET timeout=? WHERE id=? AND timeout=?", next_timeout, row[:id], row[:timeout]].update
170
+ @db.fetch("SELECT id, timeout, next_time, cron, delay, data, timezone FROM `#{@table}` WHERE timeout <= ? ORDER BY timeout ASC LIMIT #{MAX_SELECT_ROW};", now) {|row|
171
+
172
+ n = @db["UPDATE `#{@table}` SET timeout=? WHERE id=? AND timeout=?;", next_timeout, row[:id], row[:timeout]].update
189
173
  if n > 0
190
174
  scheduled_time = row[:next_time]
191
175
  attributes = create_attributes(row)
192
- task_token = Token.new(row[:id], row[:next_time], attributes[:cron], attributes[:delay], attributes[:timezone], attributes[:data].dup)
176
+ task_token = Token.new(row[:id], row[:next_time], attributes[:cron], attributes[:delay], attributes[:timezone])
193
177
  task = Task.new(@client, row[:id], attributes, scheduled_time, task_token)
194
178
  return [task]
195
179
  end
@@ -210,7 +194,7 @@ module PerfectSched
210
194
  next_run_time = now + alive_time
211
195
 
212
196
  connect {
213
- n = @db["UPDATE `#{@table}` SET timeout=? WHERE id=? AND next_time=?", next_run_time, row_id, scheduled_time].update
197
+ n = @db["UPDATE `#{@table}` SET timeout=? WHERE id=? AND next_time=?;", next_run_time, row_id, scheduled_time].update
214
198
  if n <= 0 # TODO fix
215
199
  row = @db.fetch("SELECT id, timeout, next_time FROM `#{@table}` WHERE id=? AND next_time=? LIMIT 1", row_id, scheduled_time).first
216
200
  if row == nil
@@ -229,20 +213,9 @@ module PerfectSched
229
213
  scheduled_time = task_token.scheduled_time
230
214
  next_time = PerfectSched.next_time(task_token.cron, scheduled_time, task_token.timezone)
231
215
  next_run_time = next_time + task_token.delay
232
- update_data = options[:update_data]
233
-
234
- update_sql = "UPDATE `#{@table}` SET timeout=?, next_time=?"
235
- update_params = [update_sql, next_run_time, next_time]
236
- if update_data
237
- new_data = task_token.data.merge(update_data)
238
- update_sql << ", data=?"
239
- update_params << new_data.to_json
240
- end
241
- update_sql << " WHERE id=? AND next_time=?"
242
- update_params << row_id << scheduled_time
243
216
 
244
217
  connect {
245
- n = @db[*update_params].update
218
+ n = @db["UPDATE `#{@table}` SET timeout=?, next_time=? WHERE id=? AND next_time=?;", next_run_time, next_time, row_id, scheduled_time].update
246
219
  if n <= 0
247
220
  raise IdempotentAlreadyFinishedError, "task time=#{Time.at(scheduled_time).utc} is already finished"
248
221
  end
@@ -293,6 +266,11 @@ module PerfectSched
293
266
  end
294
267
  end
295
268
 
269
+ type = data.delete('type')
270
+ if type == nil || type.empty?
271
+ type = row[:id].split(/\./, 2)[0]
272
+ end
273
+
296
274
  attributes = {
297
275
  :timezone => timezone,
298
276
  :delay => delay,
@@ -300,7 +278,9 @@ module PerfectSched
300
278
  :data => data,
301
279
  :next_time => next_time,
302
280
  :next_run_time => next_run_time,
303
- #:node => nil, # not supported
281
+ :type => type,
282
+ :message => nil, # not supported
283
+ :node => nil, # not supported
304
284
  }
305
285
  end
306
286
 
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # PerfectSched
3
3
  #
4
- # Copyright (C) 2012-2013 Sadayuki Furuhashi
4
+ # Copyright (C) 2012 FURUHASHI Sadayuki
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # PerfectSched
3
3
  #
4
- # Copyright (C) 2012-2013 Sadayuki Furuhashi
4
+ # Copyright (C) 2012 FURUHASHI Sadayuki
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -47,13 +47,14 @@ module PerfectSched
47
47
  # :data
48
48
  # :delay => 0
49
49
  # :timezone => UTC
50
- def add(key, options={})
50
+ def add(key, type, options={})
51
51
  cron = options[:cron]
52
52
 
53
53
  raise ArgumentError, ":cron option is required" unless cron
54
54
 
55
55
  delay = options[:delay] || 0
56
56
  timezone = options[:timezone] || @timezone
57
+ data = options[:data] || {}
57
58
 
58
59
  next_time = options[:next_time] || Time.now.to_i
59
60
  next_time = PerfectSched.cron_time(cron, next_time.to_i, timezone)
@@ -65,7 +66,7 @@ module PerfectSched
65
66
  next_run_time = next_time + delay
66
67
  end
67
68
 
68
- @backend.add(key, cron, delay, timezone, next_time, next_run_time, options)
69
+ @backend.add(key, type, cron, delay, timezone, data, next_time, next_run_time, options)
69
70
 
70
71
  # TODO return value
71
72
  return next_time, next_run_time
@@ -7,7 +7,7 @@ op.banner += %[ <command>
7
7
 
8
8
  commands:
9
9
  list Show list of registered schedules
10
- add <key> <cron> <data> Register a new schedule
10
+ add <key> <type> <cron> <data> Register a new schedule
11
11
  delete <key> Delete a registered schedule
12
12
  run <class> Run a worker process
13
13
  init Initialize a backend database
@@ -91,8 +91,8 @@ begin
91
91
 
92
92
  when 'add'
93
93
  cmd = :add
94
- usage nil unless ARGV.length == 3
95
- key, cron, data = *ARGV
94
+ usage nil unless ARGV.length == 4
95
+ key, type, cron, data = *ARGV
96
96
  require 'json'
97
97
  data = JSON.load(data)
98
98
 
@@ -130,11 +130,11 @@ when :list
130
130
  n = 0
131
131
  PerfectSched.open(config_load_proc.call) {|scheds|
132
132
  format = "%30s %15s %18s %7s %11s %28s %28s %s"
133
- puts format % ['key', 'cron', 'delay', 'timezone', 'next_time', 'next_run_time', 'data']
133
+ puts format % ['key', 'type', 'cron', 'delay', 'timezone', 'next_time', 'next_run_time', 'data']
134
134
  scheds.list {|sched|
135
135
  next_time = sched.next_time ? Time.at(sched.next_time) : sched.next_time
136
136
  next_run_time = sched.next_run_time ? Time.at(sched.next_run_time) : sched.next_run_time
137
- puts format % [sched.key, sched.cron, sched.delay, sched.timezone, next_time, next_run_time, sched.data]
137
+ puts format % [sched.key, sched.type, sched.cron, sched.delay, sched.timezone, next_time, next_run_time, sched.data]
138
138
  n += 1
139
139
  }
140
140
  }
@@ -149,7 +149,7 @@ when :add
149
149
  PerfectSched.open(config_load_proc.call) {|scheds|
150
150
  add_options[:cron] = cron
151
151
  add_options[:data] = data
152
- scheds.add(key, add_options)
152
+ scheds.add(key, type, add_options)
153
153
  }
154
154
 
155
155
  when :run
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # PerfectSched
3
3
  #
4
- # Copyright (C) 2012-2013 Sadayuki Furuhashi
4
+ # Copyright (C) 2012 FURUHASHI Sadayuki
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # PerfectSched
3
3
  #
4
- # Copyright (C) 2012-2013 Sadayuki Furuhashi
4
+ # Copyright (C) 2012 FURUHASHI Sadayuki
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # PerfectSched
3
3
  #
4
- # Copyright (C) 2012-2013 Sadayuki Furuhashi
4
+ # Copyright (C) 2012 FURUHASHI Sadayuki
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # PerfectSched
3
3
  #
4
- # Copyright (C) 2012-2013 Sadayuki Furuhashi
4
+ # Copyright (C) 2012 FURUHASHI Sadayuki
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # PerfectSched
3
3
  #
4
- # Copyright (C) 2012-2013 Sadayuki Furuhashi
4
+ # Copyright (C) 2012 FURUHASHI Sadayuki
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # PerfectSched
3
3
  #
4
- # Copyright (C) 2012-2013 Sadayuki Furuhashi
4
+ # Copyright (C) 2012 FURUHASHI Sadayuki
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # PerfectSched
3
3
  #
4
- # Copyright (C) 2012-2013 Sadayuki Furuhashi
4
+ # Copyright (C) 2012 FURUHASHI Sadayuki
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -49,8 +49,8 @@ module PerfectSched
49
49
  # :data => Hash
50
50
  # :cron
51
51
  # :timezone
52
- def add(key, options={})
53
- @client.add(key, options)
52
+ def add(key, type, options={})
53
+ @client.add(key, type, options)
54
54
  end
55
55
 
56
56
  def close
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # PerfectSched
3
3
  #
4
- # Copyright (C) 2012-2013 Sadayuki Furuhashi
4
+ # Copyright (C) 2012 FURUHASHI Sadayuki
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -21,6 +21,10 @@ module PerfectSched
21
21
  module ScheduleMetadataAccessors
22
22
  attr_reader :attributes
23
23
 
24
+ def type
25
+ @attributes[:type]
26
+ end
27
+
24
28
  def data
25
29
  @attributes[:data]
26
30
  end
@@ -48,6 +52,10 @@ module PerfectSched
48
52
  alias scheduled_time next_time
49
53
 
50
54
  alias scheduled_run_time next_run_time
55
+
56
+ def message
57
+ @attributes[:message]
58
+ end
51
59
  end
52
60
 
53
61
  class ScheduleMetadata
@@ -56,7 +64,6 @@ module PerfectSched
56
64
  def initialize(client, key, attributes)
57
65
  super(client)
58
66
  @key = key
59
- @attributes = attributes
60
67
  end
61
68
 
62
69
  def schedule
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # PerfectSched
3
3
  #
4
- # Copyright (C) 2012-2013 Sadayuki Furuhashi
4
+ # Copyright (C) 2012 FURUHASHI Sadayuki
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # PerfectSched
3
3
  #
4
- # Copyright (C) 2012-2013 Sadayuki Furuhashi
4
+ # Copyright (C) 2012 FURUHASHI Sadayuki
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -1,3 +1,3 @@
1
1
  module PerfectSched
2
- VERSION = "0.8.6"
2
+ VERSION = "0.8.7"
3
3
  end
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # PerfectSched
3
3
  #
4
- # Copyright (C) 2012-2013 Sadayuki Furuhashi
4
+ # Copyright (C) 2012 FURUHASHI Sadayuki
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -35,19 +35,19 @@ module PerfectSched
35
35
  end
36
36
 
37
37
  def run
38
- @log.info "PerfectSched #{VERSION}"
39
-
40
- install_signal_handlers
41
-
42
- @engine = Engine.new(@runner, load_config)
38
+ @sig = install_signal_handlers
43
39
  begin
44
- until @finished
45
- @engine.run
40
+ @engine = Engine.new(@runner, load_config)
41
+ begin
42
+ until @finished
43
+ @engine.run
44
+ end
45
+ ensure
46
+ @engine.shutdown
46
47
  end
47
48
  ensure
48
- @engine.shutdown
49
+ @sig.shutdown
49
50
  end
50
-
51
51
  return nil
52
52
  rescue
53
53
  @log.error "#{$!.class}: #{$!}"
data/perfectsched.gemspec CHANGED
@@ -10,7 +10,6 @@ Gem::Specification.new do |gem|
10
10
  gem.version = PerfectSched::VERSION
11
11
  gem.authors = ["Sadayuki Furuhashi"]
12
12
  gem.email = "frsyuki@gmail.com"
13
- gem.license = "Apache 2.0"
14
13
  gem.has_rdoc = false
15
14
  gem.files = `git ls-files`.split("\n")
16
15
  gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -23,6 +23,7 @@ describe Backend::RDBCompatBackend do
23
23
  ts.should_not == nil
24
24
  t = ts[0]
25
25
  t.data.should == {'account_id'=>1}
26
+ t.type.should == 'maint_sched'
26
27
  t.key.should == 'maint_sched.1.do_hourly'
27
28
  t.next_time.should == 1339812000
28
29
  end
@@ -32,6 +33,7 @@ describe Backend::RDBCompatBackend do
32
33
  ts = backend.acquire(60, 1, {:now=>1339812060})
33
34
  t = ts[0]
34
35
  t.data.should == {}
36
+ t.type.should == 'merge'
35
37
  t.key.should == 'merge'
36
38
  t.next_time.should == 1339812000
37
39
  end
@@ -13,28 +13,29 @@ describe ScheduleCollection do
13
13
  end
14
14
 
15
15
  it 'succeess add' do
16
- sc.add('sched01', {:cron=>'* * * * *', :timezone=>'UTC'})
16
+ sc.add('sched01', 't01', {:cron=>'* * * * *', :timezone=>'UTC'})
17
17
  end
18
18
 
19
19
  it 'fail duplicated add' do
20
- sc.add('sched01', {:cron=>'* * * * *', :timezone=>'UTC'})
20
+ sc.add('sched01', 't01', {:cron=>'* * * * *', :timezone=>'UTC'})
21
21
 
22
22
  lambda {
23
- sc.add('sched01', {:cron=>'* * * * *', :timezone=>'UTC'})
23
+ sc.add('sched01', 't01', {:cron=>'* * * * *', :timezone=>'UTC'})
24
24
  }.should raise_error AlreadyExistsError
25
25
 
26
26
  sc['sched01'].delete!
27
27
 
28
- sc.add('sched01', {:cron=>'* * * * *', :timezone=>'UTC'})
28
+ sc.add('sched01', 't01', {:cron=>'* * * * *', :timezone=>'UTC'})
29
29
  end
30
30
 
31
31
  it 'acquire' do
32
32
  time = 1323820800 # 2011-12-14 00:00:00 UTC
33
33
 
34
- s01 = sc.add('sched01', :cron=>"* * * * *", :data=>{'k'=>1}, :next_time=>time)
34
+ s01 = sc.add('sched01', 't01', :cron=>"* * * * *", :data=>{'k'=>1}, :next_time=>time)
35
35
 
36
36
  t01 = sc.poll(:alive_time=>120, :now=>time)
37
37
  t01.key.should == 'sched01'
38
+ t01.type.should == 't01'
38
39
  t01.cron.should == "* * * * *"
39
40
  t01.delay.should == 0
40
41
  t01.data.should == {'k'=>1}
@@ -47,6 +48,7 @@ describe ScheduleCollection do
47
48
 
48
49
  t04 = sc.poll(:alive_time=>120, :now=>time+60)
49
50
  t04.key.should == 'sched01'
51
+ t01.type.should == 't01'
50
52
  t04.cron.should == "* * * * *"
51
53
  t04.delay.should == 0
52
54
  t04.data.should == {'k'=>1}
@@ -56,29 +58,31 @@ describe ScheduleCollection do
56
58
  it 'timezone' do
57
59
  time = 1323820800 # 2011-12-14 00:00:00 UTC
58
60
 
59
- s01 = sc.add('sched01', :cron=>"0 0 * * *", :next_time=>time-60, :timezone=>'UTC')
61
+ s01 = sc.add('sched01', 't01', :cron=>"0 0 * * *", :next_time=>time-60, :timezone=>'UTC')
60
62
  #s01.class.should == Schedule
61
63
  #s01.key.should == 'sched01'
62
64
 
63
- s02 = sc.add('sched02', :cron=>"0 0 * * *", :next_time=>time-60, :timezone=>'Asia/Tokyo')
65
+ s02 = sc.add('sched02', 't01', :cron=>"0 0 * * *", :next_time=>time-60, :timezone=>'Asia/Tokyo')
64
66
  #s02.class.should == Schedule
65
67
  #s02.key.should == 'sched02'
66
68
 
67
69
  t01 = sc.poll(:alive_time=>86400, :now=>time)
68
70
  t01.class.should == Task
69
71
  t01.key.should == 'sched01'
72
+ t01.type.should == 't01'
70
73
  t01.scheduled_time.should == time
71
74
 
72
75
  t02 = sc.poll(:alive_time=>86400, :now=>time+54000)
73
76
  t02.class.should == Task
74
77
  t02.key.should == 'sched02'
78
+ t02.type.should == 't01'
75
79
  t02.scheduled_time.should == time+54000
76
80
  end
77
81
 
78
82
  it 'delay' do
79
83
  time = 1323820800 # 2011-12-14 00:00:00 UTC
80
84
 
81
- s01 = sc.add('sched01', :cron=>"0 * * * *", :delay=>30, :next_time=>time, :timezone=>'UTC')
85
+ s01 = sc.add('sched01', 't01', :cron=>"0 * * * *", :delay=>30, :next_time=>time, :timezone=>'UTC')
82
86
 
83
87
  t01 = sc.poll(:alive_time=>86400, :now=>time)
84
88
  t01.should == nil
@@ -86,6 +90,7 @@ describe ScheduleCollection do
86
90
  t02 = sc.poll(:alive_time=>86400, :now=>time+30)
87
91
  t02.class.should == Task
88
92
  t02.key.should == 'sched01'
93
+ t02.type.should == 't01'
89
94
  t02.scheduled_time.should == time
90
95
  t02.delay.should == 30
91
96
 
@@ -97,84 +102,38 @@ describe ScheduleCollection do
97
102
  t04 = sc.poll(:alive_time=>86400, :now=>time+3630)
98
103
  t04.class.should == Task
99
104
  t04.key.should == 'sched01'
105
+ t04.type.should == 't01'
100
106
  t04.scheduled_time.should == time+3600
101
107
  t04.delay.should == 30
102
108
  end
103
109
 
104
- it 'only_keys' do
105
- time = 1323820800 # 2011-12-14 00:00:00 UTC
106
-
107
- s01 = sc.add('sched01', :cron=>"0 * * * *", :delay=>0, :next_time=>time, :timezone=>'UTC')
108
-
109
- t01 = sc.poll(:alive_time=>86400, :now=>time, :only_keys=>['sched02'])
110
- t01.should == nil
111
-
112
- s02 = sc.add('sched02', :cron=>"0 * * * *", :delay=>0, :next_time=>time, :timezone=>'UTC')
113
-
114
- t02 = sc.poll(:alive_time=>86400, :now=>time, :only_keys=>['sched02'])
115
- t02.class.should == Task
116
- t02.key.should == 'sched02'
117
- t02.scheduled_time.should == time
118
- t02.delay.should == 0
119
-
120
- t01 = sc.poll(:alive_time=>86400, :now=>time, :only_keys=>['sched02', 'sched01'])
121
- t01.class.should == Task
122
- t01.key.should == 'sched01'
123
- t01.scheduled_time.should == time
124
- t01.delay.should == 0
125
- end
126
-
127
- it 'update_data' do
128
- time = 1323820800 # 2011-12-14 00:00:00 UTC
129
-
130
- s01 = sc.add('sched01', :cron=>"* * * * *", :data=>{'k'=>1}, :next_time=>time)
131
-
132
- t01 = sc.poll(:alive_time=>120, :now=>time)
133
- t01.data.should == {'k'=>1}
134
-
135
- t01.finish!(:update_data=>{'v'=>1})
136
-
137
- t01 = sc.poll(:alive_time=>120, :now=>time+60)
138
- t01.data.should == {'k'=>1, 'v'=>1}
139
-
140
- t01.finish!
141
-
142
- t01 = sc.poll(:alive_time=>120, :now=>time+60*2)
143
- t01.data.should == {'k'=>1, 'v'=>1}
144
-
145
- t01.finish!(:update_data=>{'k'=>2})
146
-
147
- t01 = sc.poll(:alive_time=>120, :now=>time+60*3)
148
- t01.data.should == {'k'=>2, 'v'=>1}
149
- end
150
-
151
110
  it 'invalid cron format' do
152
111
  lambda {
153
- sc.add('sched01', :cron=>'???')
112
+ sc.add('sched01', 't01', :cron=>'???')
154
113
  }.should raise_error ArgumentError
155
114
 
156
115
  lambda {
157
- sc.add('sched01', :cron=>'* * * * * *')
116
+ sc.add('sched01', 't01', :cron=>'* * * * * *')
158
117
  }.should raise_error ArgumentError
159
118
  end
160
119
 
161
120
  it 'fail duplicated add' do
162
- sc.add('sched01', :cron=>"0 * * * *")
121
+ sc.add('sched01', 't01', :cron=>"0 * * * *")
163
122
  lambda {
164
- sc.add('sched01', :cron=>"0 * * * *")
123
+ sc.add('sched01', 't01', :cron=>"0 * * * *")
165
124
  }.should raise_error AlreadyExistsError
166
125
 
167
126
  sc['sched01'].delete!
168
127
 
169
- sc.add('sched01', :cron=>"0 * * * *")
128
+ sc.add('sched01', 't01', :cron=>"0 * * * *")
170
129
  end
171
130
 
172
131
  it 'list' do
173
132
  time = 1323820800 # 2011-12-14 00:00:00 UTC
174
133
 
175
- sc.add('sched01', :cron=>"0 * * * *", :next_time=>time, :delay=>1)
176
- sc.add('sched02', :cron=>"0 * * * *", :next_time=>time, :delay=>2)
177
- sc.add('sched03', :cron=>"0 * * * *", :next_time=>time, :delay=>3, :next_run_time=>time+3600)
134
+ sc.add('sched01', 't01', :cron=>"0 * * * *", :next_time=>time, :delay=>1)
135
+ sc.add('sched02', 't02', :cron=>"0 * * * *", :next_time=>time, :delay=>2)
136
+ sc.add('sched03', 't03', :cron=>"0 * * * *", :next_time=>time, :delay=>3, :next_run_time=>time+3600)
178
137
 
179
138
  a = []
180
139
  sc.list {|s|
@@ -185,6 +144,7 @@ describe ScheduleCollection do
185
144
  s01 = a.shift
186
145
  s01.class.should == ScheduleWithMetadata
187
146
  s01.key.should == 'sched01'
147
+ s01.type.should == 't01'
188
148
  s01.cron.should == '0 * * * *'
189
149
  s01.delay.should == 1
190
150
  s01.next_time.should == time
@@ -193,6 +153,7 @@ describe ScheduleCollection do
193
153
  s02 = a.shift
194
154
  s02.class.should == ScheduleWithMetadata
195
155
  s02.key.should == 'sched02'
156
+ s02.type.should == 't02'
196
157
  s02.cron.should == '0 * * * *'
197
158
  s02.delay.should == 2
198
159
  s02.next_time.should == time
@@ -201,6 +162,7 @@ describe ScheduleCollection do
201
162
  s03 = a.shift
202
163
  s03.class.should == ScheduleWithMetadata
203
164
  s03.key.should == 'sched03'
165
+ s03.type.should == 't03'
204
166
  s03.cron.should == '0 * * * *'
205
167
  s03.delay.should == 3
206
168
  s03.next_time.should == time
data/spec/worker_spec.rb CHANGED
@@ -18,7 +18,7 @@ class TestHandler < PerfectSched::Application::Base
18
18
  end
19
19
 
20
20
  class TestApp < PerfectSched::Application::Dispatch
21
- route 'key' => TestHandler
21
+ route 'test' => TestHandler
22
22
  end
23
23
 
24
24
  describe Worker do
@@ -43,7 +43,7 @@ describe Worker do
43
43
 
44
44
  it 'run' do
45
45
  TestHandler.any_instance.should_receive(:run).once
46
- add('key', {:cron=>'* * * * *', :next_time=>Time.now.to_i-60})
46
+ add('key', 'test', {:cron=>'* * * * *', :next_time=>Time.now.to_i-60})
47
47
  sleep 2
48
48
  end
49
49
 
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.6
4
+ version: 0.8.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-04-21 00:00:00.000000000 Z
12
+ date: 2014-04-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cron-spec
@@ -155,8 +155,6 @@ files:
155
155
  - .gitignore
156
156
  - ChangeLog
157
157
  - Gemfile
158
- - LICENSE
159
- - NOTICE
160
158
  - README.md
161
159
  - Rakefile
162
160
  - bin/perfectsched
@@ -189,8 +187,7 @@ files:
189
187
  - spec/spec_helper.rb
190
188
  - spec/worker_spec.rb
191
189
  homepage: https://github.com/treasure-data/perfectsched
192
- licenses:
193
- - Apache 2.0
190
+ licenses: []
194
191
  post_install_message:
195
192
  rdoc_options: []
196
193
  require_paths:
@@ -203,7 +200,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
203
200
  version: '0'
204
201
  segments:
205
202
  - 0
206
- hash: 3128811790321973671
203
+ hash: -4078006290607887990
207
204
  required_rubygems_version: !ruby/object:Gem::Requirement
208
205
  none: false
209
206
  requirements:
@@ -212,7 +209,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
212
209
  version: '0'
213
210
  segments:
214
211
  - 0
215
- hash: 3128811790321973671
212
+ hash: -4078006290607887990
216
213
  requirements: []
217
214
  rubyforge_project:
218
215
  rubygems_version: 1.8.24
data/LICENSE DELETED
@@ -1,202 +0,0 @@
1
-
2
- Apache License
3
- Version 2.0, January 2004
4
- http://www.apache.org/licenses/
5
-
6
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
-
8
- 1. Definitions.
9
-
10
- "License" shall mean the terms and conditions for use, reproduction,
11
- and distribution as defined by Sections 1 through 9 of this document.
12
-
13
- "Licensor" shall mean the copyright owner or entity authorized by
14
- the copyright owner that is granting the License.
15
-
16
- "Legal Entity" shall mean the union of the acting entity and all
17
- other entities that control, are controlled by, or are under common
18
- control with that entity. For the purposes of this definition,
19
- "control" means (i) the power, direct or indirect, to cause the
20
- direction or management of such entity, whether by contract or
21
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
- outstanding shares, or (iii) beneficial ownership of such entity.
23
-
24
- "You" (or "Your") shall mean an individual or Legal Entity
25
- exercising permissions granted by this License.
26
-
27
- "Source" form shall mean the preferred form for making modifications,
28
- including but not limited to software source code, documentation
29
- source, and configuration files.
30
-
31
- "Object" form shall mean any form resulting from mechanical
32
- transformation or translation of a Source form, including but
33
- not limited to compiled object code, generated documentation,
34
- and conversions to other media types.
35
-
36
- "Work" shall mean the work of authorship, whether in Source or
37
- Object form, made available under the License, as indicated by a
38
- copyright notice that is included in or attached to the work
39
- (an example is provided in the Appendix below).
40
-
41
- "Derivative Works" shall mean any work, whether in Source or Object
42
- form, that is based on (or derived from) the Work and for which the
43
- editorial revisions, annotations, elaborations, or other modifications
44
- represent, as a whole, an original work of authorship. For the purposes
45
- of this License, Derivative Works shall not include works that remain
46
- separable from, or merely link (or bind by name) to the interfaces of,
47
- the Work and Derivative Works thereof.
48
-
49
- "Contribution" shall mean any work of authorship, including
50
- the original version of the Work and any modifications or additions
51
- to that Work or Derivative Works thereof, that is intentionally
52
- submitted to Licensor for inclusion in the Work by the copyright owner
53
- or by an individual or Legal Entity authorized to submit on behalf of
54
- the copyright owner. For the purposes of this definition, "submitted"
55
- means any form of electronic, verbal, or written communication sent
56
- to the Licensor or its representatives, including but not limited to
57
- communication on electronic mailing lists, source code control systems,
58
- and issue tracking systems that are managed by, or on behalf of, the
59
- Licensor for the purpose of discussing and improving the Work, but
60
- excluding communication that is conspicuously marked or otherwise
61
- designated in writing by the copyright owner as "Not a Contribution."
62
-
63
- "Contributor" shall mean Licensor and any individual or Legal Entity
64
- on behalf of whom a Contribution has been received by Licensor and
65
- subsequently incorporated within the Work.
66
-
67
- 2. Grant of Copyright License. Subject to the terms and conditions of
68
- this License, each Contributor hereby grants to You a perpetual,
69
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
- copyright license to reproduce, prepare Derivative Works of,
71
- publicly display, publicly perform, sublicense, and distribute the
72
- Work and such Derivative Works in Source or Object form.
73
-
74
- 3. Grant of Patent License. Subject to the terms and conditions of
75
- this License, each Contributor hereby grants to You a perpetual,
76
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
- (except as stated in this section) patent license to make, have made,
78
- use, offer to sell, sell, import, and otherwise transfer the Work,
79
- where such license applies only to those patent claims licensable
80
- by such Contributor that are necessarily infringed by their
81
- Contribution(s) alone or by combination of their Contribution(s)
82
- with the Work to which such Contribution(s) was submitted. If You
83
- institute patent litigation against any entity (including a
84
- cross-claim or counterclaim in a lawsuit) alleging that the Work
85
- or a Contribution incorporated within the Work constitutes direct
86
- or contributory patent infringement, then any patent licenses
87
- granted to You under this License for that Work shall terminate
88
- as of the date such litigation is filed.
89
-
90
- 4. Redistribution. You may reproduce and distribute copies of the
91
- Work or Derivative Works thereof in any medium, with or without
92
- modifications, and in Source or Object form, provided that You
93
- meet the following conditions:
94
-
95
- (a) You must give any other recipients of the Work or
96
- Derivative Works a copy of this License; and
97
-
98
- (b) You must cause any modified files to carry prominent notices
99
- stating that You changed the files; and
100
-
101
- (c) You must retain, in the Source form of any Derivative Works
102
- that You distribute, all copyright, patent, trademark, and
103
- attribution notices from the Source form of the Work,
104
- excluding those notices that do not pertain to any part of
105
- the Derivative Works; and
106
-
107
- (d) If the Work includes a "NOTICE" text file as part of its
108
- distribution, then any Derivative Works that You distribute must
109
- include a readable copy of the attribution notices contained
110
- within such NOTICE file, excluding those notices that do not
111
- pertain to any part of the Derivative Works, in at least one
112
- of the following places: within a NOTICE text file distributed
113
- as part of the Derivative Works; within the Source form or
114
- documentation, if provided along with the Derivative Works; or,
115
- within a display generated by the Derivative Works, if and
116
- wherever such third-party notices normally appear. The contents
117
- of the NOTICE file are for informational purposes only and
118
- do not modify the License. You may add Your own attribution
119
- notices within Derivative Works that You distribute, alongside
120
- or as an addendum to the NOTICE text from the Work, provided
121
- that such additional attribution notices cannot be construed
122
- as modifying the License.
123
-
124
- You may add Your own copyright statement to Your modifications and
125
- may provide additional or different license terms and conditions
126
- for use, reproduction, or distribution of Your modifications, or
127
- for any such Derivative Works as a whole, provided Your use,
128
- reproduction, and distribution of the Work otherwise complies with
129
- the conditions stated in this License.
130
-
131
- 5. Submission of Contributions. Unless You explicitly state otherwise,
132
- any Contribution intentionally submitted for inclusion in the Work
133
- by You to the Licensor shall be under the terms and conditions of
134
- this License, without any additional terms or conditions.
135
- Notwithstanding the above, nothing herein shall supersede or modify
136
- the terms of any separate license agreement you may have executed
137
- with Licensor regarding such Contributions.
138
-
139
- 6. Trademarks. This License does not grant permission to use the trade
140
- names, trademarks, service marks, or product names of the Licensor,
141
- except as required for reasonable and customary use in describing the
142
- origin of the Work and reproducing the content of the NOTICE file.
143
-
144
- 7. Disclaimer of Warranty. Unless required by applicable law or
145
- agreed to in writing, Licensor provides the Work (and each
146
- Contributor provides its Contributions) on an "AS IS" BASIS,
147
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
- implied, including, without limitation, any warranties or conditions
149
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
- PARTICULAR PURPOSE. You are solely responsible for determining the
151
- appropriateness of using or redistributing the Work and assume any
152
- risks associated with Your exercise of permissions under this License.
153
-
154
- 8. Limitation of Liability. In no event and under no legal theory,
155
- whether in tort (including negligence), contract, or otherwise,
156
- unless required by applicable law (such as deliberate and grossly
157
- negligent acts) or agreed to in writing, shall any Contributor be
158
- liable to You for damages, including any direct, indirect, special,
159
- incidental, or consequential damages of any character arising as a
160
- result of this License or out of the use or inability to use the
161
- Work (including but not limited to damages for loss of goodwill,
162
- work stoppage, computer failure or malfunction, or any and all
163
- other commercial damages or losses), even if such Contributor
164
- has been advised of the possibility of such damages.
165
-
166
- 9. Accepting Warranty or Additional Liability. While redistributing
167
- the Work or Derivative Works thereof, You may choose to offer,
168
- and charge a fee for, acceptance of support, warranty, indemnity,
169
- or other liability obligations and/or rights consistent with this
170
- License. However, in accepting such obligations, You may act only
171
- on Your own behalf and on Your sole responsibility, not on behalf
172
- of any other Contributor, and only if You agree to indemnify,
173
- defend, and hold each Contributor harmless for any liability
174
- incurred by, or claims asserted against, such Contributor by reason
175
- of your accepting any such warranty or additional liability.
176
-
177
- END OF TERMS AND CONDITIONS
178
-
179
- APPENDIX: How to apply the Apache License to your work.
180
-
181
- To apply the Apache License to your work, attach the following
182
- boilerplate notice, with the fields enclosed by brackets "[]"
183
- replaced with your own identifying information. (Don't include
184
- the brackets!) The text should be enclosed in the appropriate
185
- comment syntax for the file format. We also recommend that a
186
- file or class name and description of purpose be included on the
187
- same "printed page" as the copyright notice for easier
188
- identification within third-party archives.
189
-
190
- Copyright [yyyy] [name of copyright owner]
191
-
192
- Licensed under the Apache License, Version 2.0 (the "License");
193
- you may not use this file except in compliance with the License.
194
- You may obtain a copy of the License at
195
-
196
- http://www.apache.org/licenses/LICENSE-2.0
197
-
198
- Unless required by applicable law or agreed to in writing, software
199
- distributed under the License is distributed on an "AS IS" BASIS,
200
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
- See the License for the specific language governing permissions and
202
- limitations under the License.
data/NOTICE DELETED
@@ -1,3 +0,0 @@
1
- PerfectSched
2
- https://github.com/treasure-data/perfectsched
3
- Copyright (C) 2012-2013 Sadayuki Furuhashi