views:

74

answers:

1

Hi,

we have a modularized website built on the MVC pattern. We would like to create cronjob scripts which execute every 1, 15, 60 minutes and which execute daily. We -need- the cronjobs (to make sure nobody starts asking if we really need them).

Actions include finishing up orders for process every 15 minutes and accepting new user registrations every 60 minutes.

We have folders for controllers, models and views. These obviously contain the appropriate files for our website.

This is the global directory structure:

Root
 - /controller
 - /css
 - /js
 - /model
 - /view

/js and /css can be reached by the browser. The rest is handled by controller actions.

Now where do cronjobs fit in?

  1. Do I create seperate functions within an already existing controller? (my preference, so that code is located where it logically should)
  2. Or do I create new controllers for cronjobs?
  3. Or something else..?
+1  A: 

If you're using a framework of your own creation, then I would argue there isn't a "right" answer to this question, although there are certainly wrong answers.

If option 1 makes sense to you, and the team you're working with then it should be fine.

I will say that the framework I created for my own use I generally found that cron jobs needed enough different processing that creating dedicated controllers made more sense than trying to hang them on the outside of existing controllers. But in my case I designed the framework myself, and I'm on the only coder on the projects that use it, so I'm the only person I had to convince I'd done it right (I'm also the one that pays the price for mistakes, but that's another issue).

If you're working with an existing framework, I suggest you add that to your question and you match the design patterns of that framework.

acrosman
it's my own. Problem is i have a 'generic' route which makes it possible to execute controller actions by url... Or does this mean i should just exclude those actions from routing?
Ropstah
I try to setup my cron functions so that they are safe even if an untrusted party tries to execute them. Depending on the situation you can block people from executing things based on permissions or time (does it matter if someone else triggers an automatic job, as long as it only runs once an hour and they don't see any output?).
acrosman
I'd rather not have other people running the jobs... But I'll be able to manage from here. Thanks!
Ropstah