\midcom_services_cron

This is the handling class of the cron service. When executed, it checks all component manifests for cron jobs and runs them sequentially. The components are processed in the order they are returned by the component loader, the jobs of a single component are run in the order they are listed in the configuration array.

Cron Job configuration

Each cron job is defined by an associative array containing the following keys:

  • string handler holds the full class name which should handle the cron job invocation, it will be defined by the responsible component.
  • int recurrence must be one of MIDCOMCRON* constants.
  • string component (INTERNAL) holds the name of the component this Cron job is associated with. This key is created automatically.

The Cron service uses customdata section of the manifest, using the key midcom.services.cron as you might have guessed. So, an example cron entry could look like this:

'customdata' => Array ( 'midcom.services.cron' => Array ( Array ( 'handler' => 'net_nehmer_static_cron_test', 'recurrence' => MIDCOM_CRON_MINUTE, ) ), ),

A simple (and useless) handler class would look like this:

<?php class net_nehmer_static_cron_test extends midcom_baseclasses_components_cron_handler { function _on_initialize() { return true; }

function execute()
{
    $this->print_error("Executing...");
    $this->print_error(strftime('%x %X'));
}

}

Cron Job implementation suggestions

You should keep output to stdout to an absolute minimum. Normally, no output whatsoever should be made, as the cron service itself is invoked using some kind of Cron Daemon. Only if you output nothing, no status mail will be generated by cron.

Launching MidCOM Cron from a System Cron

You need to request the midcom-exec-midcom/cron.php page of your website to have cron running. Lynx or the GET command line tools can be used, for example, to retrieve the cron page:

lynx -source http://your.site.com/midcom-exec-midcom/cron.php
GET http://your.site.com/midcom-exec-midcom/cron.php

The script produces no output unless anything goes wrong.

Summary

Methods
Properties
Constants
__construct()
load_jobs()
execute()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
_validate_job()
_execute_job()
$_jobs
$_recurrence
N/A

Properties

$_jobs

$_jobs : array<mixed,\midcom_baseclasses_components_cron_handler>

The list of jobs to run. See the class introduction for a more precise definition of these keys.

Type

array<mixed,\midcom_baseclasses_components_cron_handler>

$_recurrence

$_recurrence : integer

The recurrence rule to use, one of the MIDCOM_CRON_* constants (MIDCOM_CRON_MINUTE, MIDCOM_CRON_HOUR, MIDCOM_CRON_DAY).

Set in the constructor

Type

integer

Methods

__construct()

__construct(  $recurrence = MIDCOM_CRON_MINUTE) 

Constructor.

Parameters

$recurrence

load_jobs()

load_jobs(array  $data) 

Load and validate all registered jobs.

After this call, all required handler classes will be available.

Parameters

array $data

The job configurations

execute()

execute() 

This is the main cron handler function.

_validate_job()

_validate_job(array  $job) : boolean

Check a jobs definition for validity.

Parameters

array $job

The job to register.

Returns

boolean —

Indicating validity.

_execute_job()

_execute_job(array  $job) 

Executes the given job.

Parameters

array $job

The job to execute.