Core:CronJob Class

From Habari Project

Jump to: navigation, search

Contents

Description

The CronJob class packages a single instance of a cron job. It extends QueryRecord.

Usage Examples

Static Functions

CronJob::default_fields()

This function is called by the class constructor to initialize the job's properties.

Public Functions

CronJob::execute()

Parameters: none
Returns: nothing

This function is called by CronTab::run() and CronTab::act_poll_cron() to execute the cron job. execute() calls the function assigned to it's *callback* field to perform the actual work of the cron job, passing all the members of the cron job and the current time to the callback function.

After the job executes, it updates it's last run time with the execution time, and adds the increment to the execution time, using the resulting value to set the time of next execution.

The result of the cron job's execution is a string stored in the cron job's *result* field. The result of the cron job's execution can be either

  • failed
  • executed

If the job executes successfully, and the execution time is greater than the job's end time, it deletes itself from the crontab table.

CronJob::insert()

Parameters: none
Returns: true on success, false on failure

Inserts the cron job into the crontab table.

CronJob::update()

Parameters: none
Returns: true on success, false on failure

Updates the cronjob with the job's new values.

CronJob::delete()

Parameters: none
Returns: true on success, false on failure

Deletes the cronjob from the crontab table.

Class Properties

  • name - string - the name of the job.
  • callback - string - the name of the function call to perform the actual work of the job.
  • increment - integer - the cron job's execution frequency in seconds. It defaults to 86400 (one day).
  • start_time - integer - the Unix time that you want the job to begin.
  • end_time - integer - the Unix time that you want the job to end.
  • cron_class - integer - The type of cron job this is. It defaults to CronJob::CRON_CUSTOM.
  • description - string - An explanation of the purpose of the job.
  • notify - string - An email address to send the results of the job's last execution. Currently, this field is ignored.
  • cron_id - integer - the job's id. It is set by the system.
  • last_run - integer - the Unix time that the job was last run. It is set by the system.
  • next_run - integer - the Unix time to run the job again. It defaults to the current time. It is set by the system.
  • result - string - the result of the job's last execution. It is set by the system.

Class Constants

The class has a set of constants which are the possible values of *cron_class*

  • CronJob::CRON_SYSTEM
  • CronJob::CRON_THEME
  • CronJob::CRON_PLUGIN
  • CronJob::CRON_CUSTOM (The default value)
This page describes a PHP class that is in the Habari software. For more comprehensive technical information visit the API Documentation.
Other Class Pages
Personal tools