-
-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathKill.php
executable file
·52 lines (46 loc) · 1.54 KB
/
Kill.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
<?php
namespace EthanYehuda\CronjobManager\Controller\Adminhtml\Manage\Job;
use EthanYehuda\CronjobManager\Api\ScheduleManagementInterface;
use Magento\Backend\App\AbstractAction;
use Magento\Backend\App\Action\Context;
class Kill extends AbstractAction
{
const ADMIN_RESOURCE = "EthanYehuda_CronjobManager::cronjobmanager";
/**
* @var ScheduleManagementInterface
*/
private $scheduleManagement;
/**
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
* @param \Magento\Backend\App\Action\Context $context
*/
public function __construct(
Context $context,
ScheduleManagementInterface $scheduleManagement
) {
parent::__construct($context);
$this->scheduleManagement = $scheduleManagement;
}
/**
* Save cronjob
*
* @return Void
*/
public function execute()
{
$jobId = (int)$this->getRequest()->getParam('id');
$jobCode = $this->getRequest()->getParam('job_code');
try {
if ($this->scheduleManagement->kill($jobId, \time())) {
$this->getMessageManager()->addSuccessMessage("Job will be killed by next cron run: {$jobCode}");
} else {
$this->getMessageManager()->addNoticeMessage("Job cannot be killed.");
}
} catch (\Exception $e) {
$this->getMessageManager()->addErrorMessage($e->getMessage());
$this->_redirect('*/manage/index/');
return;
}
$this->_redirect('*/manage/index/');
}
}