The situation:
The magazine accepts submissions. Once you submit, an editor will schedule your submission for review. Once it has been reviewed, you are no longer allowed to edit it.
So, I have submission in various states. “Draft”, “queued”, “reviewed”, etc. Most of the switches into these various states are triggered by some action, e.g., a submission becomes queued when an editor schedules it. Easy peasey. However, the switch into the “reviewed” state is not triggered by any action, it just happens after a certain datetime has passed.
I have two thoughts on how to accomplish this:
- Run a daily/hourly cron job to check up on all the queued submissions and switch them to reviewed if necessary. I dislike this because
- I would prefer it to be hourly, so that I can edit my submission up to three hours before a meeting starts
- Hourly cron jobs cost money on Heroku, and this application will either never make money or won’t make money for months and months to come
- Somehow construct a
before_loadActiveRecord callback, that will perform some logic on submissions each time they are loaded. “Queued? No? Nevermind. Otherwise, switch it to ‘Reviewed’ if its meeting is less than three hours away.”
I wanted to get people’s input on the second idea.
- Is that an atrociously smelly way to accomplish this?
- If so, can you suggest an awesomer third way?
- If ‘no’ to both of the above, can you give tips on how to perform such logic each time a record is loaded from the database? I would need to always perform some logic before doing a
selectfrom thesubmissionstable (which is gearing up to be the most-queried table in the app…)
If there’s no good way to accomplish Option Two (or, I hope!, Option Three), I will resort to Option One with a daily cron job. Being able to edit up to a day before a meeting will just have to suffice.
Maybe using after_find, although your performance will sort of suck, same goes if you do something as crazy as before_load, performance would suck, that said money might be more important than performance, if that is so, I would go with the after_find.