Ropstah
Ropstah

Reputation: 17804

Implementing cronjobs in architecture?

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..?

Upvotes: 2

Views: 188

Answers (1)

acrosman
acrosman

Reputation: 12900

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.

Upvotes: 2

Related Questions