I want to create recurring events using the Ice Cube gem in Rails - my question is, how do I then correctly, or rather efficiently, use these recurring rules for triggering actual events?
An example of this would be a recurring invoice.
Say I have an Ice Cube recurrence set for once a week and I saved it to a recurring invoice row using to_yaml. I now have a row in the database with a serialized recurrence rule. The only way I can imagine using this is to run through each and every row in the database, unserializing the saved recurrence rules and checking whether it needs to run today with schedule.occurs_on?(Date.new) - this would then be put into a cronjob that runs daily:
items = RecurringItem.find(:all)
items.each do |item|
schedule = Schedule.from_yaml(item.schedule_yaml)
if schedule.occurs_on?(Date.new)
#if today is a recurrence, do stuff!
end
end
This looks terribly inefficient to me - but I might be doing it completely wrong. Is there no better way to use Ice Cube?