lita-schedule 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -4
- data/lib/lita/lita.rb +33 -3
- data/lib/lita/schedule.rb +15 -1
- data/lib/lita/schedule/version.rb +1 -1
- 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: 8dd0935f041ad0970890bde1e14a491e38393070
|
4
|
+
data.tar.gz: 860494c709c6e3c5a1ea6603ea2225c64adff057
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4f84cae0f0b1b53443209508c5752f3e6d703a976644993297cd5c4484ab5886a2c4c124982f0764bbd632e7f07f53f88d151f3aafe753974a9e38780f5882b
|
7
|
+
data.tar.gz: 972de31762c139e78a1249dc6cfd3d24ff87cd584fc8b11007aae3884e81a2f371567bb866e5dd99bdb7618f56cba667ee1bcb8811fa15591a9e927d95aaea39
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# lita-schedule
|
2
2
|
|
3
|
-
Add base class for scheduled job (cron) to
|
3
|
+
Add base class for scheduled job (cron) to [jimmycuadra/lita](https://github.com/jimmycuadra/lita)
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -23,11 +23,11 @@ require 'lita-schedule'
|
|
23
23
|
|
24
24
|
module Lita
|
25
25
|
module Schedules
|
26
|
-
class TimeTone <
|
26
|
+
class TimeTone < Schedule
|
27
27
|
|
28
28
|
cron('* * * * * Asia/Tokyo', :every_minutes_job)
|
29
29
|
def every_minutes_job
|
30
|
-
target = Struct.new(:
|
30
|
+
target = Struct.new(:room).new('your_room@conf.hipchat.com')
|
31
31
|
robot.send_message(target, Time.now.to_s)
|
32
32
|
end
|
33
33
|
end
|
data/lib/lita/lita.rb
CHANGED
@@ -1,6 +1,38 @@
|
|
1
1
|
require 'rufus/scheduler'
|
2
2
|
|
3
3
|
module Lita
|
4
|
+
class Config < Hash
|
5
|
+
class << self
|
6
|
+
def default_config
|
7
|
+
config = new.tap do |c|
|
8
|
+
c.robot = new
|
9
|
+
c.robot.name = "Lita"
|
10
|
+
c.robot.adapter = :shell
|
11
|
+
c.robot.log_level = :info
|
12
|
+
c.robot.admins = nil
|
13
|
+
c.redis = new
|
14
|
+
c.http = new
|
15
|
+
c.http.port = 8080
|
16
|
+
c.http.debug = false
|
17
|
+
c.adapter = new
|
18
|
+
c.handlers = new
|
19
|
+
c.schedules = new # added
|
20
|
+
end
|
21
|
+
load_handler_configs(config)
|
22
|
+
load_schedule_configs(config) # added
|
23
|
+
config
|
24
|
+
end
|
25
|
+
|
26
|
+
def load_schedule_configs(config)
|
27
|
+
Lita.schedules.each do |schedule|
|
28
|
+
next unless schedule.respond_to?(:default_config)
|
29
|
+
schedule_config = config.schedules[schedule.namespace] = new
|
30
|
+
schedule.default_config(schedule_config)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
4
36
|
class << self
|
5
37
|
def schedules
|
6
38
|
@schedules ||= Set.new
|
@@ -18,9 +50,7 @@ module Lita
|
|
18
50
|
end
|
19
51
|
|
20
52
|
def register_schedules
|
21
|
-
|
22
|
-
# puts "hogehoge"
|
23
|
-
# end
|
53
|
+
|
24
54
|
Lita.schedules.each { |schedule|
|
25
55
|
schedule.jobs.each { |job|
|
26
56
|
@scheduler.cron job.cron_field do
|
data/lib/lita/schedule.rb
CHANGED
@@ -17,11 +17,25 @@ module Lita
|
|
17
17
|
def jobs
|
18
18
|
@jobs ||= []
|
19
19
|
end
|
20
|
+
|
21
|
+
def namespace
|
22
|
+
if name
|
23
|
+
Util.underscore(name.split("::").last)
|
24
|
+
else
|
25
|
+
raise "Handlers that are anonymous classes must define self.name."
|
26
|
+
end
|
27
|
+
end
|
20
28
|
end
|
21
29
|
|
22
30
|
def initialize(robot)
|
23
31
|
@robot = robot
|
24
|
-
@redis = Redis::Namespace.new(
|
32
|
+
@redis = Redis::Namespace.new(redis_namespace, redis: Lita.redis)
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def redis_namespace
|
38
|
+
"schedules:#{self.class.namespace}"
|
25
39
|
end
|
26
40
|
end
|
27
41
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lita-schedule
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- fukayatsu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-08-
|
11
|
+
date: 2013-08-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lita
|