ruboty-cron 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +2 -0
- data/lib/ruboty/cron/job.rb +15 -1
- data/lib/ruboty/cron/version.rb +1 -1
- data/lib/ruboty/handlers/cron.rb +41 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b92e5e3d8a0539b2365af2b74ef8f9ea57a5772f
|
4
|
+
data.tar.gz: dc35a238572344f256df6c56d55f77097f254678
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc7e385c6e7d35ead0b464baadfea17ac753fb6c49ca070a2d44a23f19ffd0232747711c7a7326f0adb518fc4d515e13bd2f7af5be41f56c51c4898570447f6f
|
7
|
+
data.tar.gz: 6c7e47f116b5f839071fcf6d0d74c8802aace7dd4e4f0c77734d8255c3115dc6aa3afc64e71847e5b9d11e4accacce773c7569b7f44a0e7a9395aaa805eda410
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -7,6 +7,8 @@ You can use any [Chrono](https://github.com/r7kamura/chrono/) compatible cron sy
|
|
7
7
|
```
|
8
8
|
@ruboty add job "<cron syntax>" <message> - Add a new cron job
|
9
9
|
@ruboty delete job <id> - Delete a cron job
|
10
|
+
@ruboty suspend job <id> - Suspend a cron job
|
11
|
+
@ruboty resume job <id> - Resume a cron job
|
10
12
|
@ruboty list jobs - List all cron jobs
|
11
13
|
```
|
12
14
|
|
data/lib/ruboty/cron/job.rb
CHANGED
@@ -28,8 +28,18 @@ module Ruboty
|
|
28
28
|
thread.kill
|
29
29
|
end
|
30
30
|
|
31
|
+
def suspend
|
32
|
+
stop
|
33
|
+
attributes["suspended"] = true
|
34
|
+
end
|
35
|
+
|
36
|
+
def resume(robot)
|
37
|
+
start(robot)
|
38
|
+
attributes.delete("suspended") if attributes.has_key?("suspended")
|
39
|
+
end
|
40
|
+
|
31
41
|
def description
|
32
|
-
%<%5s: "%s" %s> % [id, schedule, body]
|
42
|
+
%<%5s: (%s) "%s" %s> % [id, suspended? ? "suspended" : "active", schedule, body]
|
33
43
|
end
|
34
44
|
|
35
45
|
def id
|
@@ -43,6 +53,10 @@ module Ruboty
|
|
43
53
|
def body
|
44
54
|
attributes["body"]
|
45
55
|
end
|
56
|
+
|
57
|
+
def suspended?
|
58
|
+
!!attributes["suspended"]
|
59
|
+
end
|
46
60
|
end
|
47
61
|
end
|
48
62
|
end
|
data/lib/ruboty/cron/version.rb
CHANGED
data/lib/ruboty/handlers/cron.rb
CHANGED
@@ -9,6 +9,10 @@ module Ruboty
|
|
9
9
|
|
10
10
|
on(/list jobs\z/, name: "list", description: "List all cron jobs")
|
11
11
|
|
12
|
+
on(/suspend job (?<id>\d+)/, name: "suspend", description: "Suspend a cron job")
|
13
|
+
|
14
|
+
on(/resume job (?<id>\d+)/, name: "resume", description: "Resume a cron job")
|
15
|
+
|
12
16
|
attr_writer :jobs
|
13
17
|
|
14
18
|
def initialize(*args)
|
@@ -37,13 +41,48 @@ module Ruboty
|
|
37
41
|
message.reply(summary, code: true)
|
38
42
|
end
|
39
43
|
|
44
|
+
def suspend(message)
|
45
|
+
id = message[:id].to_i
|
46
|
+
if jobs.has_key?(id)
|
47
|
+
if running_jobs[id]
|
48
|
+
running_jobs[id].suspend
|
49
|
+
jobs[id] = running_jobs[id].to_hash
|
50
|
+
running_jobs.delete(id)
|
51
|
+
message.reply("Job #{id} suspended")
|
52
|
+
else
|
53
|
+
message.reply("Job #{id} had suspended")
|
54
|
+
end
|
55
|
+
else
|
56
|
+
message.reply("Job #{id} does not exist")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def resume(message)
|
61
|
+
id = message[:id].to_i
|
62
|
+
if jobs.has_key?(id)
|
63
|
+
job = Ruboty::Cron::Job.new(jobs[id])
|
64
|
+
if job.suspended?
|
65
|
+
job.resume(robot)
|
66
|
+
jobs[id] = job.to_hash
|
67
|
+
running_jobs[id] = job
|
68
|
+
message.reply("Job #{id} resumed")
|
69
|
+
else
|
70
|
+
message.reply("Job #{id} is running")
|
71
|
+
end
|
72
|
+
else
|
73
|
+
message.reply("Job #{id} does not exist")
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
40
77
|
private
|
41
78
|
|
42
79
|
def remember
|
43
80
|
jobs.each do |id, attributes|
|
44
81
|
job = Ruboty::Cron::Job.new(attributes)
|
45
|
-
|
46
|
-
|
82
|
+
unless job.suspended?
|
83
|
+
running_jobs[id] = job
|
84
|
+
job.start(robot)
|
85
|
+
end
|
47
86
|
end
|
48
87
|
end
|
49
88
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruboty-cron
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryo Nakamura
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|