Skip to content

Instantly share code, notes, and snippets.

/t.rb

Created April 19, 2010 12:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/370998 to your computer and use it in GitHub Desktop.
Save anonymous/370998 to your computer and use it in GitHub Desktop.
#
# config/initializers/ruote.rb
RuoteKit.configure do |c|
c.run_worker = true unless $RAKE_TASK
#c.set_storage(...
c.register do
participant 'daily' do |workitem|
Toto::Operations.trigger_inbox_reminders
end
catchall Ruote::StorageParticipant
end
end
if $RAKE_TASK != true && Rails.env != 'test'
path = Rails.root.join(*%w[ tmp pids ruote_cron_process.wfid ]).to_s
wfid = File.read(path).strip rescue nil
RuoteKit.engine.cancel_process(wfid) if wfid
wfid = RuoteKit.engine.launch(Ruote.define(:name => 'cron_process') do
cron '0 6 * * *' do
daily
end
end)
File.open(path, 'wb') { |f| f.puts(wfid) }
end
#
# lib/toto/operations.rb
module Toto
# Fires reminders for the workitems of the inbox participant.
#
def self.trigger_inbox_reminders
workitems = RuoteKit.storage_participant.by_field('remind')
users = workitems.inject({}) do |h, workitem|
if (Time.now - workitem.last_reminder) > workitem.remind_frequency
(h[workitem.user] || []) << workitem
end
h
end
users.each do |u, workitems|
::NotificationMailer.reminder(workitems)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment