webCOMAND

io_comand_systemtask\runnable

Abstract class that should be extended by a PHP File that implements the run() method that is started by a Scheduled Task.

To set up a new Scheduled Task from start to finish, see PHP Tasks.

Abstract Class

<?php
namespace io_comand_systemtask;

abstract class runnable {
    protected $repo = NULL;
    protected $task = NULL;
    protected $options = NULL;

    public function __construct(\io_comand_repo\repo $repo, array $options = []) {
        $this->repo = $repo;
        $this->options = $options;
    }

    public abstract function run(models\SystemTask $task, array $params = []);
}

Example Implementation

<?php
namespace com_package_name\runnables;

use io_comand_systemtask\runnable;
use io_comand_systemtask\models\SystemTask;

class filename extends runnable {
    public function run(SystemTask $task, array $params = []) {
        $task->log_status('Running query.');
        $items = $task->repo()->query()
            ->from($params['table'])
            ->limit($params['limit'])
            ->get();
        $task->log_notice('Got ' . count($items) . ' items.');
        foreach($items as $item) {
            if($task->is_canceling()) {
                break;
            }
            $task->log_status("Processing $item.");
        }
        $task->log_status('Completed.');
    }
}