cronman 0.0.1 → 0.0.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/cronman.gemspec +1 -1
- data/lib/cronman/entry.rb +27 -1
- data/spec/cronman/entry_spec.rb +3 -3
- metadata +1 -1
data/cronman.gemspec
CHANGED
data/lib/cronman/entry.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'digest/sha1'
|
1
2
|
require 'cron2english'
|
2
3
|
|
3
4
|
class Cronman
|
@@ -15,6 +16,7 @@ class Cronman
|
|
15
16
|
@schedule = schedule.freeze
|
16
17
|
@command = command.freeze
|
17
18
|
@cron_definition = cron_definition.freeze
|
19
|
+
@sha1 = Digest::SHA1.hexdigest(@cron_definition + ' ' + @command)
|
18
20
|
@translation = Cron2English.parse(@cron_definition).freeze
|
19
21
|
@uid =
|
20
22
|
case uid
|
@@ -29,7 +31,31 @@ class Cronman
|
|
29
31
|
end
|
30
32
|
end
|
31
33
|
|
32
|
-
|
34
|
+
def next_execution
|
35
|
+
now = Time.now
|
36
|
+
|
37
|
+
if @schedule.day_of_months_given?
|
38
|
+
# Project a year.
|
39
|
+
@schedule.from(now).until(now + 1.year).select { |t| t > now }.first
|
40
|
+
else
|
41
|
+
# Project a month.
|
42
|
+
@schedule.from(now).until(now + 1.month).select { |t| t > now }.first
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def last_execution
|
47
|
+
now = Time.now
|
48
|
+
|
49
|
+
if @schedule.day_of_months_given?
|
50
|
+
# Project a year.
|
51
|
+
@schedule.from(now - 1.year).until(now).select { |t| t < now }.last
|
52
|
+
else
|
53
|
+
# Project a month.
|
54
|
+
@schedule.from(now - 1.month).until(now).select { |t| t < now }.last
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
attr_reader :schedule, :command, :cron_definition, :translation, :uid, :sha1
|
33
59
|
class << self
|
34
60
|
# Parses a string line in crontab(5) job format.
|
35
61
|
#
|
data/spec/cronman/entry_spec.rb
CHANGED
@@ -10,19 +10,19 @@ describe Cronman::Entry do
|
|
10
10
|
@command = 'echo hello'
|
11
11
|
end
|
12
12
|
|
13
|
-
it 'should
|
13
|
+
it 'should accept Cronman::Schedule and command String' do
|
14
14
|
entry = Cronman::Entry.new(@schedule, @command, @cron_definition)
|
15
15
|
entry.uid.should == Process.uid
|
16
16
|
end
|
17
17
|
|
18
|
-
it 'should
|
18
|
+
it 'should accept Cronman::Schedule, command String and user String' do
|
19
19
|
uid = Process.uid
|
20
20
|
user = Etc.getpwuid(uid)
|
21
21
|
entry = Cronman::Entry.new(@schedule, @command, @cron_definition, user.name)
|
22
22
|
entry.uid.should == uid
|
23
23
|
end
|
24
24
|
|
25
|
-
it 'should
|
25
|
+
it 'should accept Cronman::Schedule, command String and user ID' do
|
26
26
|
uid = Process.uid
|
27
27
|
entry = Cronman::Entry.new(@schedule, @command, @cron_definition, uid)
|
28
28
|
entry.uid.should == uid
|