/**
  * @param $cronJob
  *
  * @return bool
  */
 public function getDateLastCronRun($cronJob)
 {
     $collection = $this->schelduleFactory->create()->getCollection()->addFieldToFilter('status', \Magento\Cron\Model\Schedule::STATUS_SUCCESS)->addFieldToFilter('job_code', $cronJob);
     //limit and order the results
     $collection->getSelect()->limit(1)->order('executed_at DESC');
     if ($collection->getSize() == 0) {
         return false;
     }
     //@codingStandardsIgnoreStart
     $executedAt = $collection->getFirstItem()->getExecutedAt();
     //@codingStandardsIgnoreEnd
     return $executedAt;
 }
 /**
  * @return \Magento\Backend\Model\View\Result\Redirect
  */
 public function execute()
 {
     $ids = $this->getRequest()->getParam('selected');
     if (!is_array($ids)) {
         $this->messageManager->addErrorMessage(__('Please select cron.'));
     } else {
         try {
             //@codingStandardsIgnoreStart
             foreach ($ids as $id) {
                 $model = $this->scheduleFactory->create()->setId($id);
                 $model->delete();
             }
             //@codingStandardsIgnoreEnd
             $this->messageManager->addSuccessMessage(__('Total of %1 record(s) were deleted.', count($ids)));
         } catch (\Exception $e) {
             $this->messageManager->addErrorMessage($e->getMessage());
         }
     }
     /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
     $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
     $resultRedirect->setPath('*/*/');
     return $resultRedirect;
 }
Exemplo n.º 3
0
 /**
  * @param string $jobCode
  * @param string $cronExpression
  * @param int $time
  * @return Schedule
  */
 protected function generateSchedule($jobCode, $cronExpression, $time)
 {
     $schedule = $this->_scheduleFactory->create()->setCronExpr($cronExpression)->setJobCode($jobCode)->setStatus(Schedule::STATUS_PENDING)->setCreatedAt(strftime('%Y-%m-%d %H:%M:%S', $this->timezone->scopeTimeStamp()))->setScheduledAt(strftime('%Y-%m-%d %H:%M', $time));
     return $schedule;
 }