Core:CronTab Class

From Habari Project

Revision as of 00:21, 14 January 2011 by Drzax (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Contents

Description

Similar to Unix's cron system, Habari's cron system is a flexible way to create and manage activities for the site that you wish to execute on a scheduled basis without user interaction.

When a cron job has run for the final time, it deletes itself from the database. Note that the system will not automatically run cron jobs any more frequently than every 10 minutes.

The *CronTab* class is designed as an easy to use static class that acts as an interface to the CronJob class to create and manage cron jobs. It extends ActionHandler.

Usage Examples

Static Function

CronTab::run_cron($async = false)

Parameter: $async
Returns:

Executes all the cron jobs in the database.

If $async is true, the call is referred to a new url, from which all cron jobs that are due to run execute.

If $async is false, all cron jobs that are due to run execute immediately

This function is called every time a page on a Habari powered site is requested, so if $async is false, all cron jobs that are due to run execute before the requested page is returned, while if $async is true, the requested page is returned immediately while the work of executing any cron jobs that are due is referred to a new url reserved for executing cron jobs.

CronTab::get_cronjob( $name )

Parameters: $name - string - the name of the cron job.
Returns: the cron job on success, false on failure

Gets a cron job by name from the database.

CronTab::delete_cronjob( $name )

Parameters: $name - string - the name of the cron job to delete from the crontab table
Returns: true on success, false on failure

Deletes a cron job by name from the database.

CronTab::add_cron( $paramarray )

Parameters: $paramarray - an array of the values you wish to assign to the cron job's properties.
Returns: true on success, false on failure

Adds a cron job to the database. All the other add_cron_* functions in CronTab refer the actual work to this function. The primary parameters that $paramarray can contain are

  • name - The name of the cronjob.
  • callback - The function to call to perform the cron job's work.
  • increment - The frequency of the cron job in seconds.
  • start_time - When to start the cron job. This parameter in Unix time.
  • end_time - When to stop running the cron job. This parameter is in Unix time.
  • cron_class - A constant that is a member of CronJob. See CronJob for the possible values. Normally this doesn't need to be changed from the default value.
  • description - A description of the cron job's purpose.

See CronJob for all the possible parameters $paramarray can contain.

CronTab::add_single_cron( $name, $callback, $run_time, $description = '' )

Parameters:

  • $name - string - the name you wish to assign to the cron job
  • $callback - string - the name of the function that will perform the work of the cron job
  • $run_time - integer - the Unix time to first run the cron job
  • $description - string - The purpose of the cron job

Returns: true on success, false on failure

Adds a cron job to the database that is intended to be used one time only.

CronTab::add_hourly_cron( $name, $callback, $description = '' )

Parameters:

  • $name - string - the name you wish to assign to the cron job
  • $callback - string - the name of the function that will perform the work of the cron job
  • $run_time - integer - the Unix time to first run the cron job
  • $description - string - The purpose of the cron job

Returns: true on success, false on failure

Adds a cron job to the database to run every hour.

CronTab::add_daily_cron( $name, $callback, $description = '' )

Parameters:

  • $name - string - the name you wish to assign to the cron job
  • $callback - string - the name of the function that will perform the work of the cron job
  • $run_time - integer - the Unix time to first run the cron job
  • $description - string - The purpose of the cron job

Returns: true on success, false on failure

Adds a cron job to the database to run once a day.

CronTab::add_weekly_cron( $name, $callback, $description = '' )

Parameters:

  • $name - string - the name you wish to assign to the cron job
  • $callback - string - the name of the function that will perform the work of the cron job
  • $run_time - integer - the Unix time to first run the cron job
  • $description - string - The purpose of the cron job

Returns: true on success, false on failure

Adds a cron job to the database to run once a week.

CronTab::add_monthly_cron( $name, $callback, $description = '' )

Parameters:

  • $name - string - the name you wish to assign to the cron job
  • $callback - string - the name of the function that will perform the work of the cron job
  • $run_time - integer - the Unix time to first run the cron job
  • $description - string - The purpose of the cron job

Returns: true on success, false on failure

Adds a cron job to the database to run once a month.

CronTab::act_poll_cron()

Parameters: none
Returns: nothing

act_poll_cron() is called to actually executes all cron jobs that are due to run whenever CronTab::run_cron() has been called asyncronously.

Public Functions

All functions in CronTab are static

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