I'm using Dispatcher with Laravel 4.2 for scheduling & running cron jobs.
I've added my command and it's showing in php artisan
correctly. If I run it from the terminal, it runs as expected.
As per instructions, I've added to crontab:
* * * * * php /home/tti/public_html/artisan scheduled:run 1>> /dev/null 2>&1
If I run scheduled:summary
, I can see my list as follows:
+----------------+--------------------+-----------+--------+------+--------------+-------+-------------+--------+
| Environment(s) | Name | Args/Opts | Minute | Hour | Day of Month | Month | Day of Week | Run as |
+----------------+--------------------+-----------+--------+------+--------------+-------+-------------+--------+
| * | cron:test | | * | * | * | * | * | |
+----------------+--------------------+-----------+--------+------+--------------+-------+-------------+--------+
And here's the code for the command:
<?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');
}
}
Again, everything runs correctly from the terminal command.
When I wait for the cron to fire, I get the following error in my log:
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} [] []
Why won't this run correctly?