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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4dd958d060c75fd932cf6235cfa3a1ee91b87542
4
- data.tar.gz: 43dd58785853b67fd18eada63b0f966d32e66eb6
3
+ metadata.gz: b92e5e3d8a0539b2365af2b74ef8f9ea57a5772f
4
+ data.tar.gz: dc35a238572344f256df6c56d55f77097f254678
5
5
  SHA512:
6
- metadata.gz: 40f08a59a75bc19dc3abedc14ac3d40c81f391f8ab216f370ef36be997ae60e9f16c8f7f1a844da6fbe28a06a8330be084d542e6c99907a5dd6537882b44686c
7
- data.tar.gz: 03541c379bff1772005470fb4ab5ec9686ae6e5f71239a9e58ed44c043ea10ac09e74bd7a03df33b93cac579ec1a07ffb8a0143110a8c48611d0909f02c8e577
6
+ metadata.gz: fc7e385c6e7d35ead0b464baadfea17ac753fb6c49ca070a2d44a23f19ffd0232747711c7a7326f0adb518fc4d515e13bd2f7af5be41f56c51c4898570447f6f
7
+ data.tar.gz: 6c7e47f116b5f839071fcf6d0d74c8802aace7dd4e4f0c77734d8255c3115dc6aa3afc64e71847e5b9d11e4accacce773c7569b7f44a0e7a9395aaa805eda410
@@ -1,3 +1,6 @@
1
+ ## 1.1.0
2
+ - Add suspend/resume features (#5)
3
+
1
4
  ## 1.0.2
2
5
  - Support multi lines message (#4)
3
6
 
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
 
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Ruboty
2
2
  module Cron
3
- VERSION = "1.0.2"
3
+ VERSION = "1.1.0"
4
4
  end
5
5
  end
@@ -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
- running_jobs[id] = job
46
- job.start(robot)
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.2
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-08-20 00:00:00.000000000 Z
11
+ date: 2015-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport