Commit the pile of initial work. Largely taken from company internal
repos, allowed to be newly released. Portions already in production, coverage still needs to be boosted. Enjoy. FossilOrigin-Name: 0f17fa483f55467bdf9e8f99dace58e6a90f5a8a7e595bdd79dfda5c92d16b7f
This commit is contained in:
commit
b18647f6a5
23 changed files with 2639 additions and 0 deletions
81
lib/symphony/tasks/scheduletask.rb
Normal file
81
lib/symphony/tasks/scheduletask.rb
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
#!/usr/bin/env ruby
|
||||
# vim: set nosta noet ts=4 sw=4:
|
||||
|
||||
require 'symphony'
|
||||
require 'symphony/routing'
|
||||
require 'symphony/metronome'
|
||||
|
||||
|
||||
### Accept metronome scheduling events, translating them
|
||||
### to DB rows for persistence.
|
||||
###
|
||||
class Symphony::Metronome::ScheduleTask < Symphony::Task
|
||||
include Symphony::Routing
|
||||
|
||||
queue_name 'metronome'
|
||||
timeout 30
|
||||
|
||||
### Get a handle to the database.
|
||||
###
|
||||
def initialize( * )
|
||||
@db = Symphony::Metronome::ScheduledEvent.db
|
||||
@actions = @db[ :metronome ]
|
||||
super
|
||||
end
|
||||
|
||||
# The Sequel dataset of scheduled event actions.
|
||||
attr_reader :actions
|
||||
|
||||
|
||||
### Accept a new scheduled event. The payload should be a free
|
||||
### form hash of options, along with an expression string that
|
||||
### conforms to IntervalExpression.
|
||||
###
|
||||
### {
|
||||
### :expression => 'run 25 times for an hour',
|
||||
### :payload => { ... },
|
||||
### }
|
||||
###
|
||||
on 'metronome.create' do |payload, metadata|
|
||||
raise ArgumentError, 'Invalid payload.' unless payload.is_a?( Hash )
|
||||
exp = payload.delete( 'expression' )
|
||||
raise ArgumentError, 'Missing time expression.' unless exp
|
||||
|
||||
self.actions.insert(
|
||||
:created => Time.now,
|
||||
:expression => exp,
|
||||
:options => Yajl.dump( payload )
|
||||
)
|
||||
|
||||
self.signal_parent
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
### Delete an existing scheduled event.
|
||||
### The payload is the id of the action (row) to delete.
|
||||
###
|
||||
on 'metronome.delete' do |id, metadata|
|
||||
self.actions.filter( :id => id.to_i ).delete
|
||||
self.signal_parent
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
### Tell our parent (the Metronome broadcaster) to re-read its event
|
||||
### list.
|
||||
###
|
||||
def signal_parent
|
||||
parent = Process.ppid
|
||||
|
||||
# Check to make sure we weren't orphaned.
|
||||
#
|
||||
if parent == 1
|
||||
self.log.error "Lost my parent process? Exiting."
|
||||
exit 1
|
||||
end
|
||||
|
||||
Process.kill( 'HUP', parent )
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue