Luminova Framework

PHP Luminova: Scheduling Filesystem Tasks with Novakit

Last updated: 2026-11-28 20:57:12

The Luminova Base Cron class offers advanced scheduling capabilities, allowing you to define specific controllers and methods for cron job executions.

Define filesystem-backed scheduled tasks in App\Tasks\TaskScheduler, which extends Luminova\Base\AbstractTaskScheduler. Register each command controller and method inside schedule(), then configure when it runs and where its log or output goes.

namespace App\Tasks;

use App\Controllers\Cli\DailyCommand;
use Luminova\Base\AbstractTaskScheduler;

final class TaskScheduler extends AbstractTaskScheduler
{
    protected function schedule(): void
    {
        $this->service(DailyCommand::class, 'refresh')
            ->days()
            ->log('info');
    }
}

This example assumes DailyCommand::refresh() is a public command controller method. Run Novakit from your application directory to initialize and process the scheduled tasks:

php novakit cron:create
php novakit cron:run

To check for due tasks every minute, use the application’s absolute path in the crontab entry:

* * * * * cd /path/to/app && php novakit cron:run

The interval controls when a task becomes due. The worker must be running for the task to execute.

Class Definition

  • Class namespace: Luminova\Base\AbstractTaskScheduler
  • This class is an Abstract class

Methods

constructor

Initialize constructor, additionally you can set a custom location to store cron lock file and the filename.If not set, the default location will be used which is writeable/cron/schedules.json.

public function __construct()

schedule

To define scheduled cron jobs within the extended AbstractTaskScheduler class, use this method.Called method service withing the schedule method, each service should have its own configurations.

abstract protected function schedule(): void;

service

To define a specific service for execution in a cron job, use this method to specify the namespace of your command controller and the method to be called for the job execution.

Pass the command controller class and method name as separate arguments.

protected final function service(string $class, string $method): self

Parameters:

ParameterTypeDescription
$classstringThe controller class.
$methodstringThe controller method to execute.

Return:

self - Returns the scheduler instance.

Note: Use a command controller that extends Luminova\Base\Cli\AbstractController.


onComplete

To set a callback to execute on a successful task completion.

protected final function onComplete(callable $onComplete): self

Parameters:

ParameterTypeDescription
$onCompletecallableThe callback function to execute on completion.
- Closure with one array parameter of task details.

Return:

self - Returns the scheduler instance.


onFailure

To set a callback to execute on a failure to complete task.

protected final function onFailure(callable $onError): self

Parameters:

ParameterTypeDescription
$onErrorcallableThe callback function to execute on failure.
- Closure with one array parameter of task details.

Return:

self - Returns the scheduler instance.


pingOnComplete

To set a callback URL to ping on a successful task execution.The request payload will contain the executed task details.

protected final function pingOnComplete(string $url): self

Parameters:

ParameterTypeDescription
$urlstringThe URL to ping on completion.

Return:

self - Returns the scheduler instance.


pingOnFailure

To set a callback URL to ping on a failure task execution.The request payload will contain the executed task details.

protected final function pingOnFailure(string $url): self

Parameters:

ParameterTypeDescription
$urlstringThe URL to ping on failure.

Return:

self - Returns the scheduler instance.


log

To set a log level to use in logging the execution response messages and exceptions that my occur during execution of task.

protected final function log(string $level): self

Parameters:

ParameterTypeDescription
$levelstringThe log level to use while logging execution response.

Return:

self - Returns the scheduler instance.

Log levels

You can choose any of the following log levels.

  • emergency
  • alert
  • critical
  • error
  • warning
  • notice
  • info
  • debug
  • exception
  • php_errors

output

To set a log path where all output like error messages or other exceptions that my occur during execution of task.

protected final function output(string $filepath): self

Parameters:

ParameterTypeDescription
$filepathstringThe output full path and filename.

Return:

self - Returns the scheduler instance.

This log is not related to your method, it mainly other errors that may occur due to code errors or probably PHP or framework errors.


description

Set a description for the cron task, the description will be used in logging your response.

protected final function description(string $description): self

Parameters:

ParameterTypeDescription
$descriptionstringThe description of the cron job.

Return:

self - Returns the scheduler instance.


seconds

To execute cron task at a specific seconds.

protected final function seconds(int $seconds = 5): self

Parameters:

ParameterTypeDescription
$secondsintInterval in seconds (default: 5).

Return:

self - Returns the scheduler instance.

The minimum execution time which can be set in cron is 1 minute, using this method can only be useful for debugging in development environments, if you use it in production then your task will always be executed on every call except if use set a longer seconds.


minutes

To execute cron task at a specific minutes.

protected final function minutes(int $minutes = 1): self

Parameters:

ParameterTypeDescription
$minutesintInterval in minutes.

Return:

self - Returns the scheduler instance.


hours

To execute cron task at a specific hour(s).

protected final function hours(int $hours = 1): self

Parameters:

ParameterTypeDescription
$hoursintInterval in hours.

Return:

self - Returns the scheduler instance.


days

To execute cron task at a specific day.

protected final function days(int $days = 1): self

Parameters:

ParameterTypeDescription
$daysintInterval in days.

Return:

self - Returns the scheduler instance.


weeks

To execute cron task at a specific week.

protected final function weeks(int $weeks = 1): self

Parameters:

ParameterTypeDescription
$weeksintInterval in weeks.

Return:

self - Returns the scheduler instance.


months

To execute cron task in specific month(s).

protected final function months(int $months = 1): self

Parameters:

ParameterTypeDescription
$monthsintInterval in months.

Return:

self - Returns the scheduler instance.


years

To execute cron task in specific year(s).

protected final function years(int $years = 1): self

Parameters:

ParameterTypeDescription
$yearsintInterval in years.

Return:

self - Returns the scheduler instance.


What Next?


interval

Set the DateInterval format using a date/time designator.

public function interval(string $format, int $value, string $designator): self

Parameters:

ParameterTypeDescription
$formatstringDateInterval period prefix.
$valueintThe numeric interval value.
$designatorstringDateInterval designator.

Return:

self - Returns the current instance for method chaining.


calendar

Sets a calendar-based execution date and time.

public function calendar(DateTimeInterface|string $datetime): self

Parameters:

ParameterTypeDescription
$datetimeDateTimeInterface|stringExecution date and time.

Return:

self - Returns the current instance for method chaining.


timezone

Sets the timezone used for date and time calculations.

public function timezone(DateTimeZone|string $timezone): self

Parameters:

ParameterTypeDescription
$timezoneDateTimeZone|stringTimezone instance or identifier.

Return:

self - Returns the current instance for method chaining.


expression

Set task execution interval using the cron expression.

protected final function expression(string $interval): self

Parameters:

ParameterTypeDescription
$intervalstringCron interval expression in (format: minute hour day month weekday).

Return:

self - Return instance of file task queue.


getDefinitions

Retrieves task definitions from the cron scheduler.

public final function getDefinitions(?int $id = null): array

Parameters:

ParameterTypeDescription
$id?intOptional controller ID to retrieve a specific task.

Return:

array<int,array<string,mixed>>|array<string,mixed> - Returns indexed definitions when no ID is supplied, a single definition when the ID matches, or an empty array when it does not. Read the definitions once and reuse the result when looking up multiple tasks.


taskExists

Checks whether a controller exists in the cron scheduler.

public final function taskExists(int $id): bool

Parameters:

ParameterTypeDescription
$idintController ID to check.

Return:

bool - Returns true if the controller exists, false otherwise.


getTasks

Retrieves scheduled tasks from the configuration file.

public final function getTasks(): array

Return:

array<string,array<string,mixed>> - Returns persisted task definitions keyed by the controller and method string. Each definition has the following fields.

KeyTypeDescription
idintDefinition index.
descriptionstringTask description.
controllerstringScheduled controller and method.
lastExecutionintUnix timestamp recorded for the most recent run, or the initial scheduling time.
lastRunCompletedboolWhether the previous execution completed.
completedintSuccessful execution count.
failuresintFailed execution count.
retriesintRetry count.
logstring&#124;nullConfigured log level.
outputstring&#124;nullConfigured output file path.
onFailureboolWhether a failure callback is registered.
onCompleteboolWhether a completion callback is registered.
pingOnCompletestring&#124;nullCompletion webhook URL.
pingOnFailurestring&#124;nullFailure webhook URL.
intervalarray<string,string>Interval format and timezone, when configured.