robut-cron 0.0.2 → 0.0.3
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/.gitignore +1 -0
- data/lib/robut-cron.rb +33 -9
- data/lib/robut-cron/version.rb +1 -1
- metadata +2 -2
data/.gitignore
CHANGED
data/lib/robut-cron.rb
CHANGED
@@ -4,7 +4,7 @@ class Robut::Plugin::Cron
|
|
4
4
|
include Robut::Plugin
|
5
5
|
|
6
6
|
@@skeds = Hash.new
|
7
|
-
|
7
|
+
|
8
8
|
# Returns a description of how to use this plugin
|
9
9
|
def usage
|
10
10
|
["#{at_nick} cron new * * * * * <message> - will send this message on the cron schedule",
|
@@ -27,6 +27,8 @@ class Robut::Plugin::Cron
|
|
27
27
|
reply list
|
28
28
|
when "stop"
|
29
29
|
reply stop(a[3..a.count()-1].join(" "))
|
30
|
+
when "load"
|
31
|
+
load_from_file(a[3..a.count()-1].join(" "))
|
30
32
|
else
|
31
33
|
reply "i don't understand that cron command"
|
32
34
|
end
|
@@ -39,7 +41,7 @@ class Robut::Plugin::Cron
|
|
39
41
|
scheduler = Rufus::Scheduler.start_new
|
40
42
|
job = scheduler.cron cron do |job|
|
41
43
|
|
42
|
-
if @@skeds.has_value? job
|
44
|
+
if @@skeds.has_value? job.t
|
43
45
|
connection = self.connection
|
44
46
|
reply(message)
|
45
47
|
else
|
@@ -47,7 +49,9 @@ class Robut::Plugin::Cron
|
|
47
49
|
end
|
48
50
|
|
49
51
|
end
|
50
|
-
@@skeds[message] = job
|
52
|
+
@@skeds[message] = job.t
|
53
|
+
store['jobs'] ||= []
|
54
|
+
store['jobs'] = @@skeds
|
51
55
|
reply "new cron job with id: #{message}"
|
52
56
|
rescue ArgumentError
|
53
57
|
reply "argument error, perhaps the cronline?"
|
@@ -58,23 +62,43 @@ class Robut::Plugin::Cron
|
|
58
62
|
if @@skeds.empty?
|
59
63
|
"no jobs!"
|
60
64
|
else
|
61
|
-
|
62
|
-
@@skeds.each do |key, val|
|
63
|
-
h[key] = val.t
|
64
|
-
end
|
65
|
-
|
66
|
-
h.to_s
|
65
|
+
store['jobs'].to_s
|
67
66
|
end
|
68
67
|
end
|
69
68
|
|
70
69
|
def stop(id)
|
71
70
|
if @@skeds.has_key?(id)
|
72
71
|
@@skeds.delete(id)
|
72
|
+
store['jobs'] ||= []
|
73
|
+
store['jobs'] = @@skeds
|
73
74
|
"stopping #{id}"
|
74
75
|
else
|
75
76
|
"invalid id: #{id}, can't stop that"
|
76
77
|
end
|
77
78
|
end
|
78
79
|
|
80
|
+
# load the jobs from the .robut store
|
81
|
+
# it's a bit of a chicken/egg prob so we'll
|
82
|
+
# create if it doesn't exist and leave
|
83
|
+
# it empty.
|
84
|
+
def load_from_file(file)
|
85
|
+
if !File.exist? file
|
86
|
+
reply "file does not exist"
|
87
|
+
else
|
88
|
+
begin
|
89
|
+
s = YAML.load_file(file)
|
90
|
+
if s
|
91
|
+
s['jobs'].each do |key, val|
|
92
|
+
create val,key
|
93
|
+
end
|
94
|
+
else
|
95
|
+
reply "not a valid robut config file"
|
96
|
+
end
|
97
|
+
rescue
|
98
|
+
reply "not a valid robut config file"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
79
103
|
end
|
80
104
|
|
data/lib/robut-cron/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: robut-cron
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
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: 2013-
|
12
|
+
date: 2013-10-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: robut
|