Skip to content

added possibility to specify task_key when creating a task programmatically#5

Merged
biz87 merged 1 commit intomodx-pro:masterfrom
lexsmil:patch-1
Feb 10, 2026
Merged

added possibility to specify task_key when creating a task programmatically#5
biz87 merged 1 commit intomodx-pro:masterfrom
lexsmil:patch-1

Conversation

@lexsmil
Copy link
Copy Markdown

@lexsmil lexsmil commented Apr 19, 2024

<?php
// Load the Scheduler service class
$path = $modx->getOption('scheduler.core_path', null, $modx->getOption('core_path') . 'components/scheduler/');
$scheduler = $modx->getService('scheduler', 'Scheduler', $path . 'model/scheduler/');
if (!($scheduler instanceof Scheduler)) {
    return 'Oops, could not get Scheduler service.';
}

/**
 * Get the task with reference "dosomething" in the "mycmp" namespace.
 * This task should have been added earlier via a build or the component.
 */
$task = $scheduler->getTask('mycmp', 'dosomething');
if ($task instanceof sTask) {
    // Schedule a run in 10 minutes from now
    // We're passing along an array of data; in this case a client ID.
    $task->schedule('+10 minutes', array(
        'client' => 15
    ),
    'any task key' // new feature
);
}

@biz87 biz87 merged commit 414777c into modx-pro:master Feb 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants