Reputation: 1273
If I have an Employees model and want to track how many total employees I have on every Friday and store the results in a file, is there a gem or some feature that would allow easy implementation of this?
My current plan is to use the clockwork gem (final deployment isn't on a Unix server so no Cron jobs, unfortunately) to schedule a task that simply counts the number of employees and writes that to a model.
Upvotes: 0
Views: 146
Reputation: 387
Well, If you can use cron jobs, I recommend whenever gem.
If not, I don't know your server OS but I think the OS has schedule program like crontab. So you write .rake code to generate the file has total employees. And then Input "cd /path/to/app/root/ && bundle exec rake NAMESPACE:TASK" to the schedule program by program syntax
Upvotes: 0
Reputation: 13949
I had startd to investigate this but I haven't reached the point where I need to have this.
Basically my idea was to have some "settings class" (for example using mongoid-app-settings
or the ActiveRecord equivalent), and a setup like this
class Stats
setting :my_stat
def compute_my_stat
...
end
def self.compute_statistics
[:my_stat, ...].each do |stat|
self.send("compute_"#{stat}")
end
end
end
Then you can start a rack task that would execute Stats.compute_statistics
, using the scheduler you want
Upvotes: 0
Reputation: 2951
IMHO, having a scheduled job through Cron/clockwork or Windows services would be the best way to achieve this. Your requirement states that the total has to be calculated at a certain time. This requirement has nothing to do with a web application development framework, Rails or not.
Upvotes: 1