定时任务提交
This commit is contained in:
@@ -1,31 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\command;
|
||||
|
||||
use think\console\Command;
|
||||
|
||||
class BaseCommand extends Command {
|
||||
|
||||
protected $logSave = 1; // 1: 文件,2: 打印
|
||||
|
||||
/**
|
||||
* 写入日志
|
||||
*
|
||||
* @param $type
|
||||
* @param $message
|
||||
*/
|
||||
public function log($type, $message) {
|
||||
$data = '[' . date('Y-m-d H:i:s') . ']' . PHP_EOL;
|
||||
$data .= '[' . $type . '] ' . $message . PHP_EOL . PHP_EOL;
|
||||
|
||||
if ($this->logSave === 1) {
|
||||
$name = get_class($this);
|
||||
$name = substr($name, strrpos($name, '\\') + 1);
|
||||
$file = ROOT_PATH . DS . 'runtime' . DS . $name . '_' . date('Ymd') . '.txt';
|
||||
|
||||
file_put_contents($file, $data, FILE_APPEND);
|
||||
} else {
|
||||
echo $data;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\command;
|
||||
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use think\facade\Log;
|
||||
use think\Queue;
|
||||
use app\job\DeviceListJob;
|
||||
|
||||
class DeviceListCommand extends BaseCommand
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('device:list')
|
||||
->setDescription('获取设备列表,并根据分页自动处理下一页');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
$output->writeln('开始处理设备列表任务...');
|
||||
|
||||
try {
|
||||
// 初始页码
|
||||
$pageIndex = 0;
|
||||
$pageSize = 100; // 每页获取100条记录
|
||||
|
||||
// 将第一页任务添加到队列
|
||||
$this->addToQueue($pageIndex, $pageSize);
|
||||
|
||||
$output->writeln('设备列表任务已添加到队列');
|
||||
} catch (\Exception $e) {
|
||||
Log::error('设备列表任务添加失败:' . $e->getMessage());
|
||||
$output->writeln('设备列表任务添加失败:' . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加任务到队列
|
||||
* @param int $pageIndex 页码
|
||||
* @param int $pageSize 每页大小
|
||||
*/
|
||||
protected function addToQueue($pageIndex, $pageSize)
|
||||
{
|
||||
$data = [
|
||||
'pageIndex' => $pageIndex,
|
||||
'pageSize' => $pageSize
|
||||
];
|
||||
|
||||
// 添加到队列,设置任务名为 device_list
|
||||
Queue::push(DeviceListJob::class, $data, 'device_list');
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\command;
|
||||
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
|
||||
class TestCommand extends BaseCommand {
|
||||
|
||||
protected $logSave = 2;
|
||||
|
||||
protected function configure() {
|
||||
$this->setName('Test')
|
||||
->setDescription('command test.');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output) {
|
||||
print_r('hello test.');
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class CompanyAccountModel extends Model
|
||||
{
|
||||
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class DeviceModel extends Model {
|
||||
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class FriendTaskModel extends Model
|
||||
{
|
||||
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class WechatAccountModel extends Model
|
||||
{
|
||||
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class WechatChatroomMemberModel extends Model
|
||||
{
|
||||
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class WechatChatroomModel extends Model
|
||||
{
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user