WebFioriAPI ReferenceLearnDownloadContributeLearn{{result.parent_page}} > {{result.title}}{{result.title}}Classes{{result.class_name}}{{result.summary}}Methods{{result.name}}{{result.summary}}

namespace \webfiori\framework\cron

class Cron

Class Methods Summary

public static function activeJob()Returns an object that represents the job which is currently being executed.public static function createJob(string$when, string$jobName, callable$function, array$funcParams)Creates new job using cron expression.public static function dailyJob(string$time, string$name, callable$func, array$funcParams)Creates a daily job to execute every day at specific hour and minute.public static function dayOfMonth()Returns the number of current day in the current month as integer.public static function dayOfWeek()Returns the number of current day in the current week as integer.public static function execLog(boolean$bool)Enable or disable logging for jobs execution.public static function getJob(string$jobName)Returns a job given its name.public static function getJobsNames()Returns an array that contains the names of scheduled jobs.public static function getLogArray()Returns the array that contains logged messages.public static function hour()Returns the number of current hour in the day as integer.public static function initRoutes()Creates routes to cron web interface pages.public static function jobsQueue()Returns a queue of all queued jobs.public static function log(string$message)Appends a message to the array that contains logged messages.public static function minute()Returns the number of current minute in the current hour as integer.public static function month()Returns the number of current month as integer.public static function monthlyJob(int$dayNumber, string$time, string$name, callable$func, array$funcParams)Create a job that will be executed once every month.public static function password(string$pass)Sets or gets the password that is used to protect the cron instance.public static function registerJobs()Register any CRON job which exist in the folder 'jobs' of the application.public static function run(string$pass, string|null$jobName, boolean$force, CronCommand$command)Check each scheduled job and run it if its time to run it.public static function scheduleJob(AbstractJob$job)Adds new job to jobs queue.public function setDayOfMonth(int$dayOfMonth)Sets the number of day in the month at which the scheduler started to execute jobs.public static function setDayOfWeek(int$val)Sets the value of the week at which the scheduler started to run.public function setHour(int$hour)Sets the hour at which the scheduler started to execute jobs.public function setMinute(int$minute)Sets the minute at which the scheduler started to execute jobs.public function setMonth(int$month)Sets the month at which the scheduler started to execute jobs.public static function timestamp()Returns the time at which jobs check was initialized.public static function weeklyJob(string$time, string$name, callable|null$func, array$funcParams)Creates a job that will be executed on specific time weekly.

Class Methods Details

public static function activeJob()Returns an object that represents the job which is currently being executed. Returns: CronJob|nullIf there is a job which is being executed, the method will return an object of type 'CronJob' that represent it. If no job is being executed, the method will return null.public static function createJob(string$when, string$jobName, callable$function, array$funcParams)Creates new job using cron expression. The job will be created and scheduled only if the given cron expression is valid. For more information on cron expressions, go to https://en.wikipedia.org/wiki/Cron#CRON_expression. Note that the method does not support year field. This means the expression will have only 5 fields.

Parameters:

  • string $when A cron expression.
  • string $jobName An optional job name.
  • callable $function A function to run when it is the time to execute the job.
  • array $funcParams An array of parameters that can be passed to the function.
Returns: booleanIf the job was created and scheduled, the method will return true. Other than that, the method will return false.
public static function dailyJob(string$time, string$name, callable$func, array$funcParams)Creates a daily job to execute every day at specific hour and minute.

Parameters:

  • string $time A time in the form 'hh:mm'. hh can have any value between 0 and 23 inclusive. mm can have any value between 0 and 59 inclusive.
  • string $name An optional name for the job. Can be null.
  • callable $func A function that will be executed once it is the time to run the job.
  • array $funcParams An optional array of parameters which will be passed to the callback that will be executed when its time to execute the job.
Returns: booleanIf the job was created and scheduled, the method will return true. Other than that, the method will return false.
public static function dayOfMonth()Returns the number of current day in the current month as integer. This method is used by the class 'CronJob' to validate cron job execution time.Returns: intAn integer that represents current day number in the current month.public static function dayOfWeek()Returns the number of current day in the current week as integer. This method is used by the class 'CronJob' to validate cron job execution time. The method will always return a value between 0 and 6 inclusive. 0 Means Sunday and 6 is for Saturday.Returns: intAn integer that represents current day number in the week.public static function execLog(boolean$bool)Enable or disable logging for jobs execution. This method is also used to check if logging is enabled or not. If execution log is enabled, a log file with the name 'cron.log' will be created in the folder '/logs'.

Parameters:

  • boolean $bool If set to true, a log file that contains the details of the executed jobs will be created in 'logs' folder. Default value is null.
Returns: booleanIf logging is enabled, the method will return true.
public static function getJob(string$jobName)Returns a job given its name.

Parameters:

  • string $jobName The name of the job.
Returns: CronJob|nullIf a job which has the given name was found, the method will return an object of type 'CronJob' that represents the job. Other than that, the method will return null.
public static function getJobsNames()Returns an array that contains the names of scheduled jobs. Returns: arrayAn array that contains the names of scheduled jobs.public static function getLogArray()
Returns the array that contains logged messages. The array will contain the messages which where logged using the method Cron::log()
Returns: arrayAn array of strings.
public static function hour()Returns the number of current hour in the day as integer. This method is used by the class 'CronJob' to validate cron job execution time. The method will always return a value between 0 and 23 inclusive.Returns: intAn integer that represents current hour number in the day.public static function initRoutes()
Creates routes to cron web interface pages. This method is used to initialize the following routes:
  • /cron
  • /cron/login
  • /cron/apis/{action}
  • /cron/jobs
  • /cron/jobs/{job-name}
public static function jobsQueue()Returns a queue of all queued jobs. Returns: QueueAn object of type 'Queue' which contains all queued jobs.public static function log(string$message)Appends a message to the array that contains logged messages. The main aim of the log is to help developers identify the issues which might cause a job to fail. This method can be called in any place to log a message while the code is executing.

Parameters:

  • string $message A string that act as a log message. It will be appended as passed without any changes.
public static function minute()Returns the number of current minute in the current hour as integer. This method is used by the class 'CronJob' to validate cron job execution time. The method will always return a value between 0 and 59 inclusive.Returns: intAn integer that represents current minute number in the current hour.public static function month()Returns the number of current month as integer. This method is used by the class 'CronJob' to validate cron job execution time. The method will always return a value between 1 and 12 inclusive.Returns: intAn integer that represents current month's number.public static function monthlyJob(int$dayNumber, string$time, string$name, callable$func, array$funcParams)Create a job that will be executed once every month.

Parameters:

  • int $dayNumber The day of the month at which the job will be executed on. It can have any value between 1 and 31 inclusive.
  • string $time A string that represents the time of the day that the job will execute on. The format of the time must be 'HH:MM'. where HH can have any value from '00' up to '23' and 'MM' can have any value from '00' up to '59'.
  • string $name The name of cron job.
  • callable $func A function that will be executed when its time to run the job.
  • array $funcParams An optional array of parameters which will be passed to job function.
Returns: booleanIf the job was scheduled, the method will return true. If not, the method will return false.
public static function password(string$pass)Sets or gets the password that is used to protect the cron instance. The password is used to prevent unauthorized access to execute jobs. The provided password must be 'sha256' hashed string. It is recommended to hash the password externally then use the hash inside your code.

Parameters:

  • string $pass If not null, the password will be updated to the given one.
Returns: stringIf the password is set, the method will return it. If not set, the method will return the string 'NO_PASSWORD'.
public static function registerJobs()Register any CRON job which exist in the folder 'jobs' of the application. Note that this method will register jobs only if the framework is running using CLI or the constant 'CRON_THROUGH_HTTP' is set to true.public static function run(string$pass, string|null$jobName, boolean$force, CronCommand$command)Check each scheduled job and run it if its time to run it.

Parameters:

  • string $pass If cron password is set, this value must be provided. The given value will be hashed inside the body of the method and then compared with the password which was set. Default is empty string.
  • string|null $jobName An optional job name. If specified, only the given job will be checked. Default is null.
  • boolean $force If this attribute is set to true and a job name was provided, the job will be forced to execute. Default is false.
  • CronCommand $command If cron is run from CLI, this parameter is provided to set custom execution attributes of a job.
Returns: string|arrayIf cron password is set and the given one is invalid, the method will return the string 'INV_PASS'. If a job name is specified and no job was found which has the given name, the method will return the string 'JOB_NOT_FOUND'. Other than that, the method will return an associative array which has the following indices:
  • total-jobs: Total number of scheduled jobs.
  • executed-count: Number of executed jobs.
  • successfully-completed: Number of successfully completed jobs.
  • failed: Number of jobs which did not finish successfully.
public static function scheduleJob(AbstractJob$job)Adds new job to jobs queue.

Parameters:

  • AbstractJob $job An instance of the class 'AbstractJob'.
Returns: booleanIf the job is added, the method will return true.
public function setDayOfMonth(int$dayOfMonth)Sets the number of day in the month at which the scheduler started to execute jobs. This method is helpful for the developer to test if jobs will run on the specified time or not.

Parameters:

  • int $dayOfMonth The number of day. 1 for the first day of month and 31 for the last day of the month.
public static function setDayOfWeek(int$val)Sets the value of the week at which the scheduler started to run. This method is helpful for the developer to test if jobs will run on the specified time or not.

Parameters:

  • int $val Numeric representation of the day of the week. 0 for Sunday through 6 for Saturday.
public function setHour(int$hour)Sets the hour at which the scheduler started to execute jobs. This method is helpful for the developer to test if jobs will run on the specified time or not.

Parameters:

  • int $hour The number of hour. Can be any value between 1 and 23 inclusive.
public function setMinute(int$minute)Sets the minute at which the scheduler started to execute jobs. This method is helpful for the developer to test if jobs will run on the specified time or not.

Parameters:

  • int $minute The number of the minute. Can be any value from 1 to 59.
public function setMonth(int$month)Sets the month at which the scheduler started to execute jobs. This method is helpful for the developer to test if jobs will run on the specified time or not.

Parameters:

  • int $month The number of the month. Can be any value between 1 and 12 inclusive.
public static function timestamp()Returns the time at which jobs check was initialized. Returns: stringThe method will return a time string in the format 'YY-DD HH:MM' where:
  • 'YY' is month number.
  • 'MM' is day number in the current month.
  • 'HH' is the hour.
  • 'MM' is the minute.
public static function weeklyJob(string$time, string$name, callable|null$func, array$funcParams)Creates a job that will be executed on specific time weekly.

Parameters:

  • string $time A string in the format 'd-hh:mm'. 'd' can be a number between 0 and 6 inclusive or a 3 characters day name such as 'sun'. 0 is for Sunday and 6 is for Saturday. 'hh' can have any value between 0 and 23 inclusive. mm can have any value between 0 and 59 inclusive.
  • string $name An optional name for the job. Can be null.
  • callable|null $func A function that will be executed once it is the time to run the job.
  • array $funcParams An optional array of parameters which will be passed to the function.
Returns: booleanIf the job was created and scheduled, the method will return true. Other than that, the method will return false.
mdi-menuAll Classesmdi-chevron-leftAnchorBrCodeSnippetHTMLDocHTMLListHTMLNodeHTMLTableHeadNodeInputJsCodeLabelListItemOrderedListParagraphRadioGroupTableCellTableRowUnorderedListInvalidNodeNameExceptionTemplateNotFoundExceptionCaseConverterJsonJsonConverterJsonIJsonTypesPropertyAPIFilterAbstractWebServiceManagerInfoServiceParamTypesRequestRequestParameterResponseUriWebServicesManagerAccessAutoLoaderConfigConfigControllerDBEAbstractWebServiceExtendedWebServicesManagerFileLoggerPrivilegePrivilegesGroupThemeThemeLoaderUploadFileUploaderUserUtilWebFioriAppLanguageErrorBoxHTTPCodeViewMessageBoxServerErrViewStarterPageWebPageDatabaseSessionStorageDefaultSessionStorageMSSQLSessionDataTableMSSQLSessionsTableMySQLSessionDataTableMySQLSessionsTableSessionSessionOperationsSessionStorageSessionsManagerRouterRouterUriAbstractMiddlewareMiddlewareManagerEmailMessageSMTPAccountSMTPServerClassLoaderExceptionFileExceptionInitializationExceptionInvalidCRONExprExceptionMissingLangExceptionNoSuchThemeExceptionRoutingExceptionSMTPExceptionSessionExceptionUIExceptionAbstractJobCronCronEmailCronJobJobArgumentCronLoginViewCronTasksViewCronViewCronLoginServiceCronLogoutServiceCronServicesManagerForceCronExecutionServiceGetJobsServiceCLICLICommandInputStreamOutputStreamStdInStdOutClassWriterLangClassWriterQueryClassWriterServiceHolderThemeClassWriterWebServiceWriterCreateCLIClassHelperCreateCronJobCreateMiddlewareCreateTableCreateTableObjCreateThemeHelperCreateWebServiceAddCommandCreateCommandCronCommandHelpCommandListCronCommandListRoutesCommandListThemesCommandRunSQLQueryCommandSettingsCommandTestRouteCommandUpdateSettingsCommandUpdateTableCommandVersionCommandAbstractQueryColumnColumnFactoryConditionConnectionConnectionInfoDatabaseDatabaseExceptionDateTimeValidatorEntityMapperExpressionForeignKeyJoinTableResultSetSelectExpressionTableWhereExpressionMySQLColumnMySQLConnectionMySQLQueryMySQLTableMSSQLColumnMSSQLConnectionMSSQLQueryMSSQLTableAbstractCollectionComparableLinkedListNodeQueueStack
Powered By: WebFiori Framework, Vue and VuetifyAll Rights Reserved © 2018 - 2024