swoft-cloud / swoft

🚀 PHP Microservice Full Coroutine Framework
https://swoft.org
Apache License 2.0
5.58k stars 786 forks source link

定时任务不执行 #484

Closed luguohua0394 closed 5 years ago

luguohua0394 commented 5 years ago
Q A
Bug report? yes/no
Feature request? yes/no
Swoft version 1.0.0
Swoole version 2.2.0
PHP version 7.1.4
Runtime environment Ubuntu

Details

.env 设置成CRONABLE=true 定时任务不执行,没有任何反应

<?php
/**
 * This file is part of Swoft.
 *
 * @link https://swoft.org
 * @document https://doc.swoft.org
 * @contact group@swoft.org
 * @license https://github.com/swoft-cloud/swoft/blob/master/LICENSE
 */
namespace App\Tasks;
use App\Lib\DemoInterface;
use Swoft\App;
use Swoft\Bean\Annotation\Inject;
use Swoft\HttpClient\Client;
use Swoft\Redis\Redis;
use Swoft\Rpc\Client\Bean\Annotation\Reference;
use Swoft\Task\Bean\Annotation\Scheduled;
use Swoft\Task\Bean\Annotation\Task;
/**
 * Demo task
 *
 * @Task("demo")
 */
class DemoTask
{
    /**
     * crontab定时任务
     * 每一秒执行一次
     *
     * @Scheduled(cron="* * * * * *")
     */
    public function cronTask()
    {
        App::info('111111111111111111111111111111111111111111111111111111111111111111111');
        echo time() . "每一秒执行一次  \n";
        return 'cron';
    }

    /**
     * 每分钟第3-5秒执行
     *
     * @Scheduled(cron="3-5 * * * * *")
     */
    public function cronooTask()
    {
        echo time() . "第3-5秒执行\n";
        return 'cron';
    }
}
baseSky commented 5 years ago

应该跟我的差不多,然后在断言大神的辅助下,删除beanScan配置,运行成功

luguohua0394 commented 5 years ago

打开config/properties/app.php文件,在'beanScan'数组内加入'App\Tasks',完美解决定时任务不执行问题