CronService.class.php
1.53 KB
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
59
60
61
62
<?php
/**
* 直播计划任务表
*/
namespace Common\Service;
use Common\Model\CronModel;
use VcySDK\Cron;
use VcySDK\Service;
class CronService extends AbstractService
{
// 构造方法
public function __construct()
{
$this->_d = new CronModel();
parent::__construct();
}
/**
* 创建计划任务并保存
* @param $lmId
* @param $remark
* @param $type
* @param $time
* @return bool
*/
public function createCron($lmId, $remark, $type, $time)
{
$cronSdk = new Cron(Service::instance());
// 建立 Job 发送消息
$cronResult = $cronSdk->add([
'crRemark' => $remark,
'crType' => Cron::CR_TYPE_CALLBACK,
'crParams' => json_encode([
'lm_id' => $lmId,
'type' => $type,
]),
'crMethod' => 'POST',
// 回调地址
'crReqUrl' => oaUrl('Frontend/Callback/PushMsg/Index'),
'crTimes' => 1,
'crCron' => rgmdate((String)$time, 's i G j n ? Y'),
'crMonitorExecution' => $cronSdk::CR_MONITOR_EXECUTION_FALSE,
'crDescription' => '直播开始时推送消息提醒',
]);
if (empty($cronResult['crId'])) {
E(L('_ERR_CRON_OPTION_FAILED', ['option' => '创建']));
}
// 记录计划任务
$this->_d->insert([
'lm_id' => $lmId,
'cron_id' => $cronResult['crId'],
'type' => $type
]);
return true;
}
}