-
-
Save anonymous/370998 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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