An alternative to run cron jobs that uses simple HTTP requests

Overview

SilverStripe Simple Jobs

An alternative to run cron jobs that uses simple HTTP requests.

This module require SilverStripe CronTask.

Why?

Configuring cron jobs is painful. Maybe you don't have proper access to your server, or maybe it's difficult to make sure that php is run under the right user. This is why you can simply rely on an external service to trigger a HTTP request to a given script that will take care of any task you have to run.

How to setup

Using an external service

Simply call every 5 minutes the following url : yoursite.com/simple-jobs/trigger

In order to do that, you can use for example UptimeRobot. As an added bonus, will you monitor if your webserver is responding which is always nice to have :-).

Using your own requests

Don't like using a service like UptimeRobot ? Feel free to setup your own http requets using Windows Scheduled Tasks or another server using cron.

For instance

* * * * * wget -O - http://yoursite.com/simple-jobs/trigger >/dev/null 2>&1

Using regular cron jobs

You can also use this module similarly to the base crontask module, while getting all the logging benefits.

Add the following command to your cron definition:

* * * * * www-data /usr/bin/php /path/to/silverstripe/docroot/framework/cli-script.php simple-jobs/trigger

Enabling BasicAuth

To prevent malicious users to hammer your website by calling the url, you can enable BasicAuth. Define the following in your config file:

LeKoala\SimpleJobs\SimpleJobsController:
    username: "myusername"
    password: "mypassword"

And make sure that the proper headers are sent by UptimeRobot or any system you use to trigger HTTP requests.

Testing

You can also test your tasks by visiting yoursite.com/simple-jobs/.

This is enabled only if Dev mode is active. You can click on any task in the list, and choose to run it according to its schedule or force the task to run.

If needed, you can also trigger manually your jobs. Simply visit /simple-jobs/trigger_manual/YourClass.

Log results

As an added bonus, this module will by default log all results returned by the process() method. It will be stored in the database for further analysis.

Any task returning "false" will be marked as Failed.

Any task that triggers an exception will be marked as Failed and the Exception will be stored as the result. This has also the side benefit of allowing other tasks to be run even if one of them raise an exception.

Predefined schedules

If you don't like the cron syntax, you can also use any constant from the SimpleJobSchedules class, that provides sane defaults for most common schedules.

class TestCron implements CronTask {

    /**
    * run this task every every day
    *
    * @return string
    */
    public function getSchedule() {
        return SimpleJobsSchedules::EVERY_DAY;
    }

    /**
    *
    * @return void
    */
    public function process() {
        echo 'hello';
    }
}

It also comes with two methods: everyDay and everyWeek, that allow you to define the task to run on a specific hour or day in the week. This is useful if you have multiple daily or weekly task and that you don't want to run them at the same time (because it could cause a timeout).

Simple Tasks

This module also has a limited job runner feature in form of the SimpleTask class. A simple task is simply a delayed call to a given method on a given DataObject. You can pass any number of json serializable parameters (not object instances, for example).

$task = new SimpleTask();

$task->addToTask($this, "removeStuff", [
    $some_stuff_id,
]);

One simple task can have many calls to any number of methods on any number of object instances. Keep in mind that the SimpleJobsController will only run one task each time (every 5 minutes or less depending on how you configured the module), so you may want to group in one simple task everything that is related to one specific process.

Compatibility

Tested with 4.4+

Maintainer

LeKoala - [email protected]

You might also like...
Calibre OPDS (and HTML) PHP Server : web-based light alternative to Calibre content server / Calibre2OPDS to serve ebooks (epub, mobi, pdf, ...)

COPS COPS stands for Calibre OPDS (and HTML) Php Server. See : COPS's home for more details. Don't forget to check the Wiki. Why ? In my opinion Calib

An article about alternative solution for convert object into a JSON Object for your api.

Do we really need a serializer for our JSON API? The last years I did build a lot of JSON APIs but personally was never happy about the magic of using

Highly customizable alternative to var_export for PHP code generation

PHP Variable Exporter PHPEncoder is a PHP library for exporting variables and generating PHP code representations for said variables similar to the bu

Ethereal Billing System is meant to be used as a personal alternative to WHMCS.
Ethereal Billing System is meant to be used as a personal alternative to WHMCS.

Ethereal Billing System is meant to be used as a personal alternative to WHMCS. In no way is this as good or even better than WHMCS apart from the fact that is free and open source to the public.

A simple package for idempotent requests in Laravel.

📽 Replay A simple package for handling idempotent requests in Laravel. Any routes using the Replay middleware will check for whether an incoming requ

Greyhole uses Samba to create a storage pool of all your available hard drives, and allows you to create redundant copies of the files you store.

Greyhole Greyhole is an application that uses Samba to create a storage pool of all your available hard drives (whatever their size, however they're c

the repository uses some of the code from php-meminfo to simplify integration

the repository uses some of the code from php-meminfo to simplify integration

Uses internet-connectable temperature sensors to provide cooling/heating assist for small buildings, as well as weather data

ambient-hvac Uses internet-connectable temperature sensors to provide cooling/heating assist for houses and other small buildings, as well as weather

This library uses GD and EXIF (optional) PHP extensions so make sure you have them installed.

simple and fast image processing class that can downscale, compress and convert images using php-gd native functions

Comments
  • Separate out logging or make URL trigger optional

    Separate out logging or make URL trigger optional

    Thanks for this nice module. While I like the simplicity of having recurring jobs triggered from an external URL, this also imposes some limits (I think). For example the maximum allowed time spent handling a request is usually 30-60 seconds, after which the process times out. Also adds a dependency on an external system, of course.

    Hence it might be interesting to make the URL-triggering optional and also facilitate direct cron-based triggering. What you'd gain compared to the regular crontask module, is visibility of the results in the database (a crucial plus, if you ask me).

    Another option might be to separate out the result-logging into its own module which could then be added onto the regular crontask module as well? Not sure if which route would be best (if at all interested).

    Oh, you might be interested in my silverstripe-cronkeep module which adds a web-based crontask editing interface.

    opened by micschk 1
Releases(2.0.4)
Owner
Thomas Portelange
Web developer
Thomas Portelange
This project processes a small database with php all on a web server. This project uses XAMPP to run the web server and the database.

PHP-introduction This project processes a small database with php all on a web server. This project uses XAMPP to run the web server and the database.

Tyler Jacques 1 Jan 6, 2022
Run your WP site on github pages, php innovation award winner https://www.phpclasses.org/package/12091-PHP-Make-a-WordPress-site-run-on-GitHub-pages.html

Gitpress Run wordpress directly on github pages Gitpress won the innovation award for may 2021 Read more about this https://naveen17797.github.io/gitp

naveen 13 Nov 18, 2022
⚓️ Easily test HTTP webhooks with this handy tool that displays requests instantly.

Webhook.site With Webhook.site, you instantly get a unique, random URL that you can use to test and debug Webhooks and HTTP requests, as well as to cr

Webhook.site 3.7k Jan 9, 2023
Magento 2 - Cron Scheduler by KiwiCommerce

We're not maintaining this extension, if you need any support please contact us at [email protected] Magento 2 - Cron Scheduler by KiwiCommerce

KiwiCommerce 76 Sep 28, 2022
This repository contains the codebase PHP bridge using RoadRunner Jobs plugin.

RoadRunner Jobs Plugin This repository contains the codebase PHP bridge using RoadRunner Jobs plugin. Installation To install application server and J

Spiral Scout 15 Nov 9, 2022
Kirby 3 Plugin for running jobs like cleaning the cache from within the Panel, PHP code, CLI or a cronjob

Kirby 3 Janitor Kirby 3 Plugin for running jobs. It is a Panel Button! It has jobs build-in for cleaning the cache, sessions, create zip-backup, pre-g

Bruno Meilick 68 Dec 21, 2022
Simple game server with php without socket programming. Uses the Api request post(json).

QMA server Simple game server with php without socket programming. Uses the Api request post(json). What does this code do? Register the user as a gue

reza malekpour 3 Sep 4, 2021
An alternative Redis session handler for PHP featuring per-session locking and session fixation protection

RedisSessionHandler An alternative Redis session handler featuring session locking and session fixation protection. News phpredis v4.1.0 (released on

Marcel Hernandez 117 Oct 19, 2022
A self-hosted alternative to putting your code snippets on Gist.

WP-Gistpen Contributors: JamesDiGioia Donate link: http://jamesdigioia.com/ Tags: gist, code snippets, codepen Requires at least: 5.2 Requires PHP: 5.

Intraxia 71 Nov 15, 2022
Alternative to tmpfile() function

TmpFile Alternative to tmpfile() function. Installation You can install the latest version via Composer: composer require denisyukphp/tmpfile This pa

Aleksandr Denisyuk 22 Sep 7, 2022