示例#1
0
 public function stop($jobDescription)
 {
     try {
         $this->resqueManager->delete($jobDescription);
     } catch (\Exception $e) {
     }
 }
 /**
  * @dataProvider getValues
  */
 public function testDeleteNow($name, $options, $queue, $when)
 {
     $job = $this->manager->put($name, $options, $queue);
     $this->assertEquals(0, $this->manager->delete($job));
 }
 /**
  * Called to start the queued task
  *
  * @param array $options
  * @throws \Exception
  */
 public function execute(array $options = null)
 {
     $userId = (int) $options['userId'];
     $date = $options['date'];
     //2015-07-23  Y-m-d
     $checkNum = (int) $options['checkNum'];
     $user = $this->em->getRepository('RedmineAppBundle:RedmineUser')->find($userId);
     $spentHours = $this->client->getSpentTime($user->getRedmineToken(), $date, $user->getRedmineUserID());
     if ($spentHours == 0) {
         $notificationMessage = "On {$date} you don't track your time!";
     } else {
         $notificationMessage = "On {$date} you tracked only {$spentHours} hours.";
     }
     if ($checkNum == 1) {
         if ($spentHours < 7) {
             if ($user->getSettings()->isPush()) {
                 $this->sendPush($user, $notificationMessage);
             }
             if ($user->getSettings()->isSms() and $user->getSettings()->getPhone()) {
                 $this->sendSMS($user, $notificationMessage);
             }
         }
         $nextDate = Carbon::now();
         $nextDate->startOfDay()->hour((int) $user->getSettings()->getCheckSecond()->format('H'))->minute((int) $user->getSettings()->getCheckSecond()->format('i'));
         $job = $this->resqueManager->put('redmine.timeChecker', ['userId' => $user->getId(), 'date' => $nextDate->format('Y-m-d'), 'checkNum' => 2], $this->queueName, $nextDate);
         $user->setJobDescription($job);
         $this->em->flush();
     }
     if ($checkNum == 2) {
         if ($spentHours < 7) {
             if ($user->getSettings()->isPush()) {
                 $this->sendPush($user, $notificationMessage);
             }
             if ($user->getSettings()->isSms() and $user->getSettings()->getPhone()) {
                 $this->sendSMS($user, $notificationMessage);
             }
         }
         $nextDate = Carbon::createFromFormat('Y-m-d', $date);
         $nextDate->addDay();
         if ($nextDate->dayOfWeek == Carbon::SATURDAY) {
             $nextDate->addDays(2);
         } elseif ($nextDate->dayOfWeek == Carbon::SUNDAY) {
             $nextDate->addDays(1);
         }
         $nextDate->startOfDay()->hour((int) $user->getSettings()->getCheckThird()->format('H'))->minute((int) $user->getSettings()->getCheckThird()->format('i'));
         $job = $this->resqueManager->put('redmine.timeChecker', ['userId' => $user->getId(), 'date' => $date, 'checkNum' => 3], $this->queueName, $nextDate);
         $user->setJobDescription($job);
         $this->em->flush();
     }
     if ($checkNum == 3) {
         if ($spentHours < 7) {
             if ($user->getSettings()->isPush()) {
                 $this->sendPush($user, $notificationMessage);
             }
             if ($user->getSettings()->isSms() and $user->getSettings()->getPhone()) {
                 $this->sendSMS($user, $notificationMessage);
             }
         }
         $nextDate = Carbon::now();
         $nextDate->startOfDay()->hour((int) $user->getSettings()->getCheckFirst()->format('H'))->minute((int) $user->getSettings()->getCheckFirst()->format('i'));
         $job = $this->resqueManager->put('redmine.timeChecker', ['userId' => $user->getId(), 'date' => $nextDate->format('Y-m-d'), 'checkNum' => 1], $this->queueName, $nextDate);
         $user->setJobDescription($job);
         $this->em->flush();
     }
 }