rsched 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +7 -0
- data/README.rdoc +5 -0
- data/lib/rsched/command/rsched.rb +11 -1
- data/lib/rsched/dblock.rb +22 -9
- data/lib/rsched/engine.rb +6 -6
- data/lib/rsched/lock.rb +1 -1
- data/lib/rsched/version.rb +1 -1
- data/test/sched_test.rb +1 -1
- metadata +4 -4
data/ChangeLog
CHANGED
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
|
-
|
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
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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(
|
24
|
-
while @last_time <=
|
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
|
-
|
84
|
+
sched_time = Time.now.to_i - @delay
|
85
85
|
@ss.each_pair {|ident,s|
|
86
86
|
|
87
|
-
s.sched(
|
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
data/lib/rsched/version.rb
CHANGED
data/test/sched_test.rb
CHANGED
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:
|
4
|
+
hash: 17
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
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
|
+
date: 2011-07-20 00:00:00 +09:00
|
19
19
|
default_executable: rsched
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|