/**
  * Adds a job to the queue to be started
  * 
  * Relevant data about the job will be persisted using a QueuedJobDescriptor
  *
  * @param QueuedJob $job 
  *			The job to start.
  * @param $startAfter
  *			The date (in Y-m-d H:i:s format) to start execution after
  * @param int $userId
  *			The ID of a user to execute the job as. Defaults to the current user
  */
 public function queueJob(QueuedJob $job, $startAfter = null, $userId = null, $queueName = null)
 {
     $signature = $job->getSignature();
     // see if we already have this job in a queue
     $filter = array('Signature' => $signature, 'JobStatus' => QueuedJob::STATUS_NEW);
     $existing = DataList::create('QueuedJobDescriptor')->filter($filter)->first();
     if ($existing && $existing->ID) {
         return $existing->ID;
     }
     $jobDescriptor = new QueuedJobDescriptor();
     $jobDescriptor->JobTitle = $job->getTitle();
     $jobDescriptor->JobType = $queueName ? $queueName : $job->getJobType();
     $jobDescriptor->Signature = $signature;
     $jobDescriptor->Implementation = get_class($job);
     $jobDescriptor->StartAfter = $startAfter;
     $jobDescriptor->RunAsID = $userId ? $userId : Member::currentUserID();
     // copy data
     $this->copyJobToDescriptor($job, $jobDescriptor);
     $jobDescriptor->write();
     if ($startAfter && strtotime($startAfter) > time()) {
     } else {
         // immediately start it on the queue, however that works
         $this->queueHandler->startJobOnQueue($jobDescriptor);
     }
     return $jobDescriptor->ID;
 }
 /**
  * Start a job (or however the queue handler determines it should be started)
  *
  * @param JobDescriptor $jobDescriptor
  * @param date $startAfter
  */
 public function startJob($jobDescriptor, $startAfter = null)
 {
     if ($startAfter && strtotime($startAfter) > time()) {
         $this->queueHandler->scheduleJob($jobDescriptor, $startAfter);
     } else {
         // immediately start it on the queue, however that works
         $this->queueHandler->startJobOnQueue($jobDescriptor);
     }
 }