-
Notifications
You must be signed in to change notification settings - Fork 224
/
Copy pathScheduleCommand.php
58 lines (49 loc) · 1.98 KB
/
ScheduleCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
namespace N98\Magento\Command\System\Cron;
use Magento\Cron\Model\Schedule;
use Magento\Framework\App\Area;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class ScheduleCommand extends AbstractCronCommand
{
protected function configure()
{
$this
->setName('sys:cron:schedule')
->addArgument('job', InputArgument::OPTIONAL, 'Job code')
->setDescription('Schedule a cronjob for execution right now, by job code');
$help = <<<HELP
If no `job` argument is passed you can select a job from a list.
HELP;
$this->setHelp($help);
}
/**
* @param InputInterface $input
* @param OutputInterface $output
* @throws \Exception
* @return int|void
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->state->setAreaCode(Area::AREA_CRONTAB);
$objectManager = $this->getObjectManager();
$configLoader = $objectManager->get('Magento\Framework\ObjectManager\ConfigLoaderInterface');
$objectManager->configure($configLoader->load(Area::AREA_CRONTAB));
list($jobCode, $jobConfig) = $this->getJobForExecuteMethod($input, $output);
$output->write(
'<info>Scheduling </info><comment>' . $jobConfig['instance'] . '::' . $jobConfig['method'] . '</comment> '
);
$createdAtTime = $this->timezone->scopeTimeStamp();
$scheduledAtTime = $createdAtTime;
/* @var $schedule \Magento\Cron\Model\Schedule */
$schedule = $this->cronScheduleCollection->getNewEmptyItem();
$schedule
->setJobCode($jobCode)
->setStatus(Schedule::STATUS_PENDING)
->setCreatedAt(strftime('%Y-%m-%d %H:%M:%S', $createdAtTime))
->setScheduledAt(strftime('%Y-%m-%d %H:%M', $scheduledAtTime))
->save();
$output->writeln('<info>done</info>');
}
}