我正在使用Dispatcher与Laravel 4.2进行日程安排&运行cron工作。
我添加了我的命令,它正确显示在php artisan
中。如果我从终端运行它,它会按预期运行。
根据说明,我已添加到crontab:
* * * * * php /home/tti/public_html/artisan scheduled:run 1>> /dev/null 2>&1
如果我运行scheduled:summary
,我可以看到我的列表如下:
+----------------+--------------------+-----------+--------+------+--------------+-------+-------------+--------+
| Environment(s) | Name | Args/Opts | Minute | Hour | Day of Month | Month | Day of Week | Run as |
+----------------+--------------------+-----------+--------+------+--------------+-------+-------------+--------+
| * | cron:test | | * | * | * | * | * | |
+----------------+--------------------+-----------+--------+------+--------------+-------+-------------+--------+
这是命令的代码:
<?php
use Indatus\Dispatcher\Scheduling\ScheduledCommand;
use Indatus\Dispatcher\Scheduling\Schedulable;
use Indatus\Dispatcher\Drivers\Cron\Scheduler;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
class DatabaseBackup extends ScheduledCommand {
/**
* The console command name.
*
* @var string
*/
protected $name = 'wtf:test';
/**
* The console command description.
*
* @var string
*/
protected $description = 'This is a test.';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* When a command should run
*
* @param Scheduler $scheduler
* @return \Indatus\Dispatcher\Scheduling\Schedulable
*/
public function schedule(Schedulable $scheduler)
{
// return $scheduler;
return $scheduler
->daily()
->hours(3)
->minutes(20);
}
/**
* Execute the console command.
*
* @return mixed
*/
public function fire()
{
Log::info('Cron test successful');
}
}
同样,一切都从终端命令正确运行。
当我等待cron触发时,我的日志中出现以下错误:
local.ERROR: exception 'InvalidArgumentException' with message 'There are no commands defined in the "wtf" namespace.' in /home/tti/public_html/vendor/symfony/console/Symfony/Component/Console/Application.php:514
Stack trace:
#0 /home/tti/public_html/vendor/symfony/console/Symfony/Component/Console/Application.php(548): Symfony\Component\Console\Application->findNamespace('wtf')
#1 /home/tti/public_html/vendor/symfony/console/Symfony/Component/Console/Application.php(188): Symfony\Component\Console\Application->find('wtf:databasebac...')
#2 /home/tti/public_html/vendor/symfony/console/Symfony/Component/Console/Application.php(121): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#3 /home/tti/public_html/artisan(58): Symfony\Component\Console\Application->run()
#4 {main} [] []
[2016-08-13 15:35:01] local.ERROR: exception 'InvalidArgumentException' with message 'There are no commands defined in the "wtf" namespace.' in /home/tti/public_html/vendor/symfony/console/Symfony/Component/Console/Application.php:514
Stack trace:
#0 /home/tti/public_html/vendor/symfony/console/Symfony/Component/Console/Application.php(548): Symfony\Component\Console\Application->findNamespace('cron')
#1 /home/tti/public_html/vendor/symfony/console/Symfony/Component/Console/Application.php(188): Symfony\Component\Console\Application->find('wtf:databasebac...')
#2 /home/tti/public_html/vendor/symfony/console/Symfony/Component/Console/Application.php(121): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#3 /home/tti/public_html/artisan(58): Symfony\Component\Console\Application->run()
#4 {main} [] []
为什么这不能正确运行?