- ⌂ System Task
- Methods
- Static Methods
SystemTask::is_canceling()
Returns whether or not this task is canceling. That is, it has been canceled, but its underlying logic has not yet halted. It is the responsibility of the code that implements a System Task to periodically check this function and gracefully stop processing if it returns TRUE.
A System Task can be cancelled from the Notifications & Tasks sidebar, the daemon CLI, with set_canceled() or set_canceling(), or if a Scheduled Task Timeout is reached and it has an On Timeout set to "Cancel Process".
Prototype
boolean is_canceling()
Return
Returns TRUE if the System Task has been canceled, but not yet stopped. Otherwise FALSE.
Example
/**
* "Runnable" class to define a background System Task that will
* process objects, but stop gracefully if canceled.
*/
use io_comand_systemtask\models\SystemTask;
use io_comand_systemtask\runnable;
use io_comand_systemtask\event\type;
class my_bg_process extends runnable {
public function run(SystemTask $task, array $params = []) {
$task->log_status('Starting process...');
// run process...
$objects = $task->repo()->get('FROM MyObject WHERE Active');
foreach($objects as $object) {
if($task->is_canceling()) {
$task->log_notice('Process cancelled.');
break;
}
$task->log_status("Processing Object (OID $object->OID)");
// do some processing
$task->log_result(
type::SUCCESS,
"Processed Object (OID $object->OID).",
'url',
'https://example.webcomand.com/?cpath=' . $object->OID
);
}
}
}