/** * Test method call */ public function testGetJobs() { $jobList = ['jobname1' => ['instance' => 'TestInstance', 'method' => 'testMethod', 'schedule' => '* * * * *']]; $this->_configData->expects($this->once())->method('getJobs')->will($this->returnValue($jobList)); $result = $this->_config->getJobs(); $this->assertEquals($jobList, $result); }
public function execute() { if (!$this->_isAllowed()) { echo $this->__('Access Denied'); return; } $SCHEDULE_EVERY_MINUTES = 30; //Flooring the minutes $startTimeSeconds = (int) ($this->_timezone->scopeTimeStamp() / 60) * 60; //Ceiling to the next 5 minutes $startTimeMinutes = $startTimeSeconds / 60; $startTimeMinutes = (int) ($startTimeMinutes / 5) * 5 + 5; $startTimeSeconds = $startTimeMinutes * 60; $jobs = $this->_cronConfig->getJobs(); if (isset($jobs[self::CRON_GROUP])) { $i = 0; foreach ($jobs[self::CRON_GROUP] as $jobCode => $jobConfig) { if (strpos($jobCode, self::CRON_JOB) === false) { continue; } $timecreated = strftime('%Y-%m-%d %H:%M:%S', $this->_timezone->scopeTimeStamp()); $timescheduled = strftime('%Y-%m-%d %H:%M:%S', $startTimeSeconds + $i * 60 * $SCHEDULE_EVERY_MINUTES); try { $lastItem = $this->_cronSchedule->getCollection()->addFieldToFilter('job_code', 'celebros_export')->addFieldToFilter('scheduled_at', $timescheduled)->getLastItem(); if (!$lastItem->getScheduleId()) { $this->_cronSchedule->setJobCode($jobCode)->setCreatedAt($timecreated)->setScheduledAt($timescheduled)->setStatus('pending')->save(); echo "{$jobCode} cron job is scheduled at {$timescheduled} <br/>"; } else { echo "{$jobCode} cron job are already exist at {$timescheduled} <br/>"; } } catch (\Exception $e) { throw new \Exception(__('Unable to schedule Cron')); } $i++; } } }