MVC and cron jobs


I have a cronjob that runs “ruby script/runner ‘Channel.preload’”.
Channel is a parent model, Item is the child model (i.e., Channel
has_many :items and Item belongs_to :channel). The coupling is
minimized, the coherence looks good, but I’m not sure the model is the
right place to put this code. Is there a better place to put this
code, e.g., a component (I don’t really understand components and
attempts to use them haven’t worked as expected/advertised). The code
could go in a module, i.e., all the added code is class methods.



Without knowing what you’re doing, it looks fine. Script/runner is
going to give you access to anything in your rails application so what
you’re doing should be fine.

However, my solution was to create a class called ‘Run’ and put all
of the commands that would be called from outside of the web app in
that class. It helped me keep things organized a bit better.