ellen-cron 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +11 -0
- data/Rakefile +2 -0
- data/ellen-cron.gemspec +24 -0
- data/lib/ellen/cron/job.rb +53 -0
- data/lib/ellen/cron/version.rb +5 -0
- data/lib/ellen/cron.rb +3 -0
- data/lib/ellen/handlers/cron.rb +76 -0
- metadata +124 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 64268f41dc8d52a47f3e2c4e346508ea1414d0c5
|
4
|
+
data.tar.gz: 581838d20cbf1fd07178fd3ac0ff7290b713ae0d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6eb4900b9e8ce376fce3e3d1a17012b61ffee430b2baaab080eee9afa8d9ed92fd898b9cf88bcaf6dd03ae38d593f7cecdd781507900b8dc9d989987053cc217
|
7
|
+
data.tar.gz: 49a6c557e7af063403c196837b0b2b9f7c055e78bf52afda23b92fb30978d03615c968e43af50c591ac8f75fcd9f014ed985fcaeb8eda5579a40b8bc4836f7df
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Ryo Nakamura
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# Ellen::Cron
|
2
|
+
Mount cron system to [Ellen]("https://github.com/r7kamura/ellen") to schedule messages on a specific time.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
You can use any [Chrono](https://github.com/r7kamura/chrono/) compatible cron syntax to schedule messages.
|
6
|
+
|
7
|
+
```
|
8
|
+
@ellen add job "<cron syntax>" <message> - Add a new cron job
|
9
|
+
@ellen delete job <id> - Delete a cron job
|
10
|
+
@ellen list jobs - List all cron jobs
|
11
|
+
```
|
data/Rakefile
ADDED
data/ellen-cron.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "ellen/cron/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "ellen-cron"
|
7
|
+
spec.version = Ellen::Cron::VERSION
|
8
|
+
spec.authors = ["Ryo Nakamura"]
|
9
|
+
spec.email = ["r7kamura@gmail.com"]
|
10
|
+
spec.summary = "Mount cron system to Ellen to schedule messages on a specific time."
|
11
|
+
spec.homepage = "https://github.com/r7kamura/ellen-cron"
|
12
|
+
spec.license = "MIT"
|
13
|
+
|
14
|
+
spec.files = `git ls-files -z`.split("\x0")
|
15
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
|
+
spec.require_paths = ["lib"]
|
18
|
+
|
19
|
+
spec.add_dependency "activesupport"
|
20
|
+
spec.add_dependency "chrono"
|
21
|
+
spec.add_dependency "ellen", ">= 0.0.8"
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require "active_support/core_ext/hash/keys"
|
2
|
+
require "chrono"
|
3
|
+
require "json"
|
4
|
+
|
5
|
+
module Ellen
|
6
|
+
module Cron
|
7
|
+
class Job
|
8
|
+
attr_reader :attributes, :thread
|
9
|
+
|
10
|
+
def initialize(attributes)
|
11
|
+
@attributes = attributes.stringify_keys
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_json
|
15
|
+
to_hash.to_json
|
16
|
+
end
|
17
|
+
|
18
|
+
def start(robot)
|
19
|
+
@thread = Thread.new do
|
20
|
+
Chrono::Trigger.new(schedule) do
|
21
|
+
robot.say(body)
|
22
|
+
end.run
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def stop
|
27
|
+
thread.kill
|
28
|
+
end
|
29
|
+
|
30
|
+
def description
|
31
|
+
%<%5s: "%s" %s> % [id, schedule, body]
|
32
|
+
end
|
33
|
+
|
34
|
+
def id
|
35
|
+
attributes["id"]
|
36
|
+
end
|
37
|
+
|
38
|
+
def schedule
|
39
|
+
attributes["schedule"]
|
40
|
+
end
|
41
|
+
|
42
|
+
def body
|
43
|
+
attributes["body"]
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def to_hash
|
49
|
+
attributes.to_json
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/ellen/cron.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
module Ellen
|
2
|
+
module Handlers
|
3
|
+
class Cron < Base
|
4
|
+
on(/add job "(.+)" (.+)/, name: "add", description: "Add a new cron job")
|
5
|
+
|
6
|
+
on(/delete job (\d+)/, name: "delete", description: "Delete a cron job")
|
7
|
+
|
8
|
+
on(/list jobs\z/, name: "list", description: "List all cron jobs")
|
9
|
+
|
10
|
+
attr_writer :jobs
|
11
|
+
|
12
|
+
def add(message)
|
13
|
+
job = create(message)
|
14
|
+
robot.say "Job #{job.id} created"
|
15
|
+
end
|
16
|
+
|
17
|
+
def delete(message)
|
18
|
+
id = message[1].to_i
|
19
|
+
if jobs.has_key?(id)
|
20
|
+
jobs[id].stop
|
21
|
+
jobs.delete(id)
|
22
|
+
push
|
23
|
+
robot.say "Job #{id} deleted"
|
24
|
+
else
|
25
|
+
robot.say "Job #{id} does not exist"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def list(message)
|
30
|
+
robot.say jobs_list
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def pull
|
36
|
+
self.jobs = robot.brain.data["cron"].inject({}) do |result, (id, attributes)|
|
37
|
+
result.merge(id => Ellen::Cron::Job.new(attributes))
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def push
|
42
|
+
robot.brain.data["cron"] = jobs.inject({}) do |result, (id, job)|
|
43
|
+
result.merge(id => job.to_json)
|
44
|
+
end
|
45
|
+
robot.brain.save
|
46
|
+
end
|
47
|
+
|
48
|
+
def jobs
|
49
|
+
@jobs ||= {}
|
50
|
+
end
|
51
|
+
|
52
|
+
def create(message)
|
53
|
+
job = Ellen::Cron::Job.new(id: generate_id, schedule: message[1], body: message[2])
|
54
|
+
jobs[job.id] = job
|
55
|
+
push
|
56
|
+
job.start(robot)
|
57
|
+
job
|
58
|
+
end
|
59
|
+
|
60
|
+
def jobs_list
|
61
|
+
if jobs.empty?
|
62
|
+
"Jobs not found"
|
63
|
+
else
|
64
|
+
jobs.values.map(&:description).join("\n")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def generate_id
|
69
|
+
loop do
|
70
|
+
id = rand(10000)
|
71
|
+
break id unless jobs.has_key?(id)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ellen-cron
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ryo Nakamura
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: chrono
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: ellen
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.0.8
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.0.8
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.6'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.6'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- r7kamura@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- Gemfile
|
92
|
+
- LICENSE.txt
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- ellen-cron.gemspec
|
96
|
+
- lib/ellen/cron.rb
|
97
|
+
- lib/ellen/cron/job.rb
|
98
|
+
- lib/ellen/cron/version.rb
|
99
|
+
- lib/ellen/handlers/cron.rb
|
100
|
+
homepage: https://github.com/r7kamura/ellen-cron
|
101
|
+
licenses:
|
102
|
+
- MIT
|
103
|
+
metadata: {}
|
104
|
+
post_install_message:
|
105
|
+
rdoc_options: []
|
106
|
+
require_paths:
|
107
|
+
- lib
|
108
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
requirements: []
|
119
|
+
rubyforge_project:
|
120
|
+
rubygems_version: 2.2.2
|
121
|
+
signing_key:
|
122
|
+
specification_version: 4
|
123
|
+
summary: Mount cron system to Ellen to schedule messages on a specific time.
|
124
|
+
test_files: []
|