Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+11 votes
2.0k views
in Plugins by
edited by

This is a simple plugin that is mostly intended for developers. Basically, Q2A has no support for cron, although it allows its integration. However, configuring a cron process is something the average user does not know how to do. So I thought that, although cron is irreplaceable, a workaround could be implemented that would work for most scenarios in which cron is needed.

So suppose you need to perform an action. Let's take, for instance, a table clean up. You could perform a DELETE statement on every request. Or maybe you could implement a counter that would execute the DELETE statement after a given amount of requests, in order to decrease server load.

Well, this plugin does exactly that. It fires an event after a given amount of requests. So all it is needed is to register an event module and make sure it listens to the event the plugin fires. This way, you just need to focus on the actions you need to perform (the DELETE) and how often you want them to be run (every 400 requests).

Additionally, the plugin can fire events on a daily, weekly and monthly basis. These events are, again, generated based on a request, however, they are limited to run only once per time period.

Again, the plugin does not care at all about time. Only about server requests, which may or may not be the same for the actions needed by other plugins.

Plugin features:

  • An event is fired every a 100 requests
  • An event is fired once daily, weekly and monthly (provided a request has been performed)
  • Avoids performing a given operation (checking files, running database queries, sending an email, checking server status, etc) on each request
  • No need of core hacks or plugin overrides
  • Simple installation

Plugin notes:

  • This plugin is no replacement of cron and does fire any event based on the time factor
  • The plugin is intended to be installed by Q2A admins but actually used by developers
  • There are several technical details in the GitHub repository that should not be overlooked
  • Works on Q2A version 1.6 and later

You can give it a try downloading it from the GitHub project page.

Q2A version: 1.6+
by
+1 for the ncie plugin
by
Important note: I skipped cronjobs for the best-users-plugin in favor of listening to events and then storing the user points in an extra table. In production mode, there was a problem though. This did not always work.

I was wondering and came to the conclusion that anonymous users (or bots) visit the site and leave it quickly. Thus the server does not execute the command. I might be wrong ... but I could fix this by only checking for events of registered users. No problems anymore in storing the user points in the database.
by
@pupi1985 Interesting idea! Have you thought about making it time-based? If you only get a few page views a day there will be a much longer gap between running the "cron" than if you have several hundred or thousand views.

So you would just keep track of the last time it was run, then the first request after X hours would run it again.
by
@q2apro.com I don't fully get your comment. The server will execute the process regardless of the fact that the request belongs to a logged in user or not. It doesn't also matter whether the site is left quickly or not (the server just doesn't know what happens in the client side unless it is notified)

@Scott The plugin was originally thought to handle maintenance tasks, which are focused on site usage, rather than functional requirements. Anyway, it is true that there could be some time dependant (but not strictly time sensitive) scenarios in which that would make sense. For example, if you wanted to show a daily quote and you already have a plugin that fetched the quote and displays it in the site having the quote change more than once a day can be controlled within the plugin itself. However, as you say, if the amount of requests don't hit the minimum in the day the quote change won't be fired. I'll look into this
by
Thanks... Nice plugin.
by
Nice try. I will also use CRON in automatic maintenance feature of my DMP.
http://www.question2answer.org/qa/40782
Virtual CRON of wordpress will help to improvement. However, although you already know, this mechanism is not suitable for heavy synchronization processing. And, there will be required to consider event log plugin. I will cheer your development.
by
Thanks @sama @Funrunna.

I ended up adding the daily, weekly and monthly execution limits as well. I hope it is more useful this way :)

Please log in or register to answer this question.

...