rsched 0.3.0 → 0.3.1

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,11 @@
1
1
 
2
+ == 2011-07-20 version 0.3.1
3
+
4
+ * Run task exactly at XX:XX:00
5
+ * Use InnoDB on MySQL
6
+ * Show kind message when DBI driver is not found
7
+
8
+
2
9
  == 2011-07-19 version 0.3.0
3
10
 
4
11
  * Changed not to release a lock when a task is failed
data/README.rdoc CHANGED
@@ -32,6 +32,11 @@ _Example:_
32
32
  # Run every day at 00:00
33
33
  $ rsched -a 'mywork 0 0 * * * aaaa uuu ee' ...
34
34
 
35
+ # Use SQLite3 for the lock database
36
+ $ rsched -T mysql -H myhost -D mydb -u myuser -p mypassword ...
37
+
38
+ # Use MySQL for the lock database
39
+ $ rsched -T sqlite3 -D /path/to/db.sqlite3 ...
35
40
 
36
41
  == Usage
37
42
 
@@ -243,7 +243,17 @@ if conf[:daemon]
243
243
  end
244
244
 
245
245
 
246
- lock = RSched::DBLock.new(conf[:name], conf[:timeout], dbi, conf[:db_user].to_s, conf[:db_password].to_s)
246
+ begin
247
+ lock = RSched::DBLock.new(conf[:name], conf[:timeout], dbi, conf[:db_user].to_s, conf[:db_password].to_s)
248
+ rescue DBI::InterfaceError
249
+ STDERR.puts "Can't initialize DBI interface: #{$!}"
250
+ STDERR.puts "You may have to install database driver first:"
251
+ STDERR.puts ""
252
+ STDERR.puts " $ gem install dbd-mysql"
253
+ STDERR.puts " $ gem install dbd-sqlite3"
254
+ STDERR.puts ""
255
+ exit 1
256
+ end
247
257
  worker = RSched::Engine.new(lock, conf)
248
258
 
249
259
  schedule.each {|e|
data/lib/rsched/dblock.rb CHANGED
@@ -7,18 +7,31 @@ class DBLock < Lock
7
7
  super(hostname, timeout)
8
8
  require 'dbi'
9
9
  @db = DBI.connect(uri, user, pass)
10
- init_db
10
+ init_db(uri.split(':',3)[1])
11
11
  end
12
12
 
13
- def init_db
13
+ def init_db(type)
14
14
  sql = ''
15
- sql << 'CREATE TABLE IF NOT EXISTS rsched ('
16
- sql << ' ident VARCHAR(256) NOT NULL,'
17
- sql << ' time INT NOT NULL,'
18
- sql << ' host VARCHAR(256),'
19
- sql << ' timeout INT,'
20
- sql << ' finish INT,'
21
- sql << ' PRIMARY KEY (ident, time));'
15
+ case type
16
+ when /mysql/i
17
+ sql << 'CREATE TABLE IF NOT EXISTS rsched ('
18
+ sql << ' ident VARCHAR(256) CHARACTER SET ASCII NOT NULL,'
19
+ sql << ' time INT NOT NULL,'
20
+ sql << ' host VARCHAR(256) CHARACTER SET ASCII,'
21
+ sql << ' timeout INT,'
22
+ sql << ' finish INT,'
23
+ sql << ' PRIMARY KEY (ident, time)'
24
+ sql << ') ENGINE=INNODB;'
25
+ else
26
+ sql << 'CREATE TABLE IF NOT EXISTS rsched ('
27
+ sql << ' ident VARCHAR(256) NOT NULL,'
28
+ sql << ' time INT NOT NULL,'
29
+ sql << ' host VARCHAR(256),'
30
+ sql << ' timeout INT,'
31
+ sql << ' finish INT,'
32
+ sql << ' PRIMARY KEY (ident, time)'
33
+ sql << ');'
34
+ end
22
35
  @db.execute(sql)
23
36
  end
24
37
 
data/lib/rsched/engine.rb CHANGED
@@ -14,14 +14,14 @@ class Engine
14
14
  @action = action
15
15
  @sched_start = sched_start
16
16
  @queue = []
17
- @last_time = from
17
+ @last_time = from.to_i / 60 * 60
18
18
  sched(to)
19
19
  end
20
20
 
21
21
  attr_reader :queue, :action
22
22
 
23
- def sched(now)
24
- while @last_time <= now
23
+ def sched(sched_time)
24
+ while @last_time <= sched_time
25
25
  t = Time.at(@last_time).utc
26
26
  if @tab.is_specification_in_effect?(t)
27
27
  time = create_time_key(t)
@@ -68,7 +68,7 @@ class Engine
68
68
  # {cron => (ident,action)}
69
69
  def set_sched(ident, action, cron)
70
70
  now = Time.now.to_i
71
- @ss[ident] = Sched.new(cron, action, @sched_start, now-@resume, now-@delay)
71
+ @ss[ident] = Sched.new(cron, action, @sched_start, now-@delay-@resume, now-@delay)
72
72
  end
73
73
 
74
74
  def init_proc(run_proc, kill_proc)
@@ -81,10 +81,10 @@ class Engine
81
81
  until @finished
82
82
  one = false
83
83
 
84
- now = Time.now.to_i - @delay
84
+ sched_time = Time.now.to_i - @delay
85
85
  @ss.each_pair {|ident,s|
86
86
 
87
- s.sched(now)
87
+ s.sched(sched_time)
88
88
  s.queue.delete_if {|time|
89
89
  next if @finished
90
90
 
data/lib/rsched/lock.rb CHANGED
@@ -14,7 +14,7 @@ class Lock
14
14
  def acquire(ident, time, now=Time.now.to_i)
15
15
  end
16
16
 
17
- def release(token, next_timeout=Time.now.to_i)
17
+ def release(token)
18
18
  end
19
19
 
20
20
  def finish(token, now=Time.now.to_i)
@@ -1,5 +1,5 @@
1
1
  module RSched
2
2
 
3
- VERSION = '0.3.0'
3
+ VERSION = '0.3.1'
4
4
 
5
5
  end
data/test/sched_test.rb CHANGED
@@ -39,7 +39,7 @@ class SchedTest < Test::Unit::TestCase
39
39
  assert_equal [now, now+HOUR, now+HOUR*3], sched.queue
40
40
  end
41
41
 
42
- it 'sched hours' do
42
+ it 'sched days' do
43
43
  now = Time.parse("2010-02-02 00:00:00 UTC").to_i
44
44
  sched_start = now
45
45
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rsched
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 0
10
- version: 0.3.0
9
+ - 1
10
+ version: 0.3.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sadayuki Furuhashi
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-07-18 00:00:00 +09:00
18
+ date: 2011-07-20 00:00:00 +09:00
19
19
  default_executable: rsched
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency