We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 20215
    • 144 Posts
    https://www.modmore.com/extras/scheduler/documentation/scheduling-task/

    is there a way to schedule a run in 10 minutes from now, only if there are no other already scheduled of the same task?

    thx
      ----------------------------------
      canale irc Italiano #modx server: tophost.azzurra.org
      • 38415 ☆ A M B ☆
      • 70 Posts
      Hi, sure… you just need a snippet/plugin/task that does something like this:

      $taskId = 1; // ENTER YOUR TASK-ID HERE
      
      $c = $modx->newQuery('sTaskRun');
      $c->where(array(
          'status' => 0,
          'task' => $taskId
      ));
      $taskRuns = $modx->getCollection('sTaskRun', $c);
      
      if (count($taskRuns) == 0) {
          $task = $modx->getObject('sTask', $taskId);
          $task->schedule(strtotime('+10min'));
      }


      The code is not tested but hopefully should work. I've used something similar before.
        chsmedien - Digital Marketing Agency
        MODX Professional & Ambassador

        http://chsmedien.com | http://twitter.com/christianseel
        • 18373 ☆ A M B ☆
        • 3,141 Posts
            $task = $scheduler->getTask('gitifywatch', 'extract');
            if ($task instanceof sTask) {
                // Try to find one already scheduled
                $run = $modx->getObject('sTaskRun', array(
                    'task' => $task->get('id'),
                    'status' => sTaskRun::STATUS_SCHEDULED,
                ));
        
                if ($run instanceof sTaskRun) {
                    // already scheduled
                } else {
                    $task->schedule($time, array(
                        'triggers' => array($trigger),
                    ));
                }
            }
            else {
                $modx->log(modX::LOG_LEVEL_ERROR, 'Could not find sTask gitifywatch:extract');
            }
          Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

          Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
          • 20215
          • 144 Posts
          WOW! laugh thanks a lot guys!!!
            ----------------------------------
            canale irc Italiano #modx server: tophost.azzurra.org