<?php


namespace App\Console\Commands\Push;


use App\Modules\Push\Models\QappPushTask;
use App\Modules\Push\Services\PushService;
use Illuminate\Console\Command;

class PushTask extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'push:task';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '每分钟执行推送任务';

    /**
     * @return bool
     * @throws \App\Exceptions\ApiException
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function handle()
    {
        // 获取待推送的任务
        $pushTask = QappPushTask::getValidTask();
        $taskId   = getProp($pushTask, 'id');
        if (!$taskId) {
            return false;
        }

        // 执行推送
        PushService::pushMessageByTaskId($taskId);
    }

}