symphony-metronome 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.rdoc +198 -0
- data/bin/metronome-exp +33 -0
- data/data/symphony-metronome/migrations/20140419_initial.rb +32 -0
- data/lib/symphony/metronome.rb +79 -0
- data/lib/symphony/metronome/intervalexpression.rb +2518 -0
- data/lib/symphony/metronome/mixins.rb +130 -0
- data/lib/symphony/metronome/scheduledevent.rb +174 -0
- data/lib/symphony/metronome/scheduler.rb +156 -0
- data/lib/symphony/tasks/scheduletask.rb +81 -0
- metadata +141 -0
@@ -0,0 +1,81 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# vim: set nosta noet ts=4 sw=4:
|
3
|
+
|
4
|
+
require 'symphony'
|
5
|
+
require 'symphony/routing'
|
6
|
+
require 'symphony/metronome'
|
7
|
+
|
8
|
+
|
9
|
+
### Accept metronome scheduling events, translating them
|
10
|
+
### to DB rows for persistence.
|
11
|
+
###
|
12
|
+
class Symphony::Metronome::ScheduleTask < Symphony::Task
|
13
|
+
include Symphony::Routing
|
14
|
+
|
15
|
+
queue_name 'metronome'
|
16
|
+
timeout 30
|
17
|
+
|
18
|
+
### Get a handle to the database.
|
19
|
+
###
|
20
|
+
def initialize( * )
|
21
|
+
@db = Symphony::Metronome::ScheduledEvent.db
|
22
|
+
@actions = @db[ :metronome ]
|
23
|
+
super
|
24
|
+
end
|
25
|
+
|
26
|
+
# The Sequel dataset of scheduled event actions.
|
27
|
+
attr_reader :actions
|
28
|
+
|
29
|
+
|
30
|
+
### Accept a new scheduled event. The payload should be a free
|
31
|
+
### form hash of options, along with an expression string that
|
32
|
+
### conforms to IntervalExpression.
|
33
|
+
###
|
34
|
+
### {
|
35
|
+
### :expression => 'run 25 times for an hour',
|
36
|
+
### :payload => { ... },
|
37
|
+
### }
|
38
|
+
###
|
39
|
+
on 'metronome.create' do |payload, metadata|
|
40
|
+
raise ArgumentError, 'Invalid payload.' unless payload.is_a?( Hash )
|
41
|
+
exp = payload.delete( 'expression' )
|
42
|
+
raise ArgumentError, 'Missing time expression.' unless exp
|
43
|
+
|
44
|
+
self.actions.insert(
|
45
|
+
:created => Time.now,
|
46
|
+
:expression => exp,
|
47
|
+
:options => Yajl.dump( payload )
|
48
|
+
)
|
49
|
+
|
50
|
+
self.signal_parent
|
51
|
+
return true
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
### Delete an existing scheduled event.
|
56
|
+
### The payload is the id of the action (row) to delete.
|
57
|
+
###
|
58
|
+
on 'metronome.delete' do |id, metadata|
|
59
|
+
self.actions.filter( :id => id.to_i ).delete
|
60
|
+
self.signal_parent
|
61
|
+
return true
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
### Tell our parent (the Metronome broadcaster) to re-read its event
|
66
|
+
### list.
|
67
|
+
###
|
68
|
+
def signal_parent
|
69
|
+
parent = Process.ppid
|
70
|
+
|
71
|
+
# Check to make sure we weren't orphaned.
|
72
|
+
#
|
73
|
+
if parent == 1
|
74
|
+
self.log.error "Lost my parent process? Exiting."
|
75
|
+
exit 1
|
76
|
+
end
|
77
|
+
|
78
|
+
Process.kill( 'HUP', parent )
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
metadata
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: symphony-metronome
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mahlon E. Smith <mahlon@martini.nu>
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: symphony
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.6'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sequel
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sqlite3
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.8'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.8'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: timecop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.7'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.7'
|
97
|
+
description: "\t\tMetronome is a scheduler and task runner. It can be used locally
|
98
|
+
as a\n\t\tcron replacement, or as a network-wide job executor. Events are stored\n\t\tvia
|
99
|
+
simple database rows, and optionally managed via AMQP events.\n\t\tInterval/time
|
100
|
+
values are expressed with reasonably intuitive English\n\t\tphrases, ie.: 'at 2pm',
|
101
|
+
or 'Starting in 20 minutes, run every 10 seconds\n\t\tand then finish in 2 days'.\n"
|
102
|
+
email: mahlon@martini.nu
|
103
|
+
executables:
|
104
|
+
- metronome-exp
|
105
|
+
extensions: []
|
106
|
+
extra_rdoc_files: []
|
107
|
+
files:
|
108
|
+
- README.rdoc
|
109
|
+
- bin/metronome-exp
|
110
|
+
- data/symphony-metronome/migrations/20140419_initial.rb
|
111
|
+
- lib/symphony/metronome.rb
|
112
|
+
- lib/symphony/metronome/intervalexpression.rb
|
113
|
+
- lib/symphony/metronome/mixins.rb
|
114
|
+
- lib/symphony/metronome/scheduledevent.rb
|
115
|
+
- lib/symphony/metronome/scheduler.rb
|
116
|
+
- lib/symphony/tasks/scheduletask.rb
|
117
|
+
homepage: http://projects.martini.nu/ruby-modules
|
118
|
+
licenses:
|
119
|
+
- BSD
|
120
|
+
metadata: {}
|
121
|
+
post_install_message:
|
122
|
+
rdoc_options: []
|
123
|
+
require_paths:
|
124
|
+
- lib
|
125
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - '>='
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: 2.0.0
|
130
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - '>='
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: 2.0.3
|
135
|
+
requirements: []
|
136
|
+
rubyforge_project:
|
137
|
+
rubygems_version: 2.2.2
|
138
|
+
signing_key:
|
139
|
+
specification_version: 4
|
140
|
+
summary: A natural language scheduling and task runner.
|
141
|
+
test_files: []
|