I'm using Indatus/dispatcher for Laravel 4.2. It is basically a Cron job based Task Scheduler.
I am trying to run a Cron job every minute, and I am getting this error on the live server (but it works fine on my local machine). Here is what I have done:
<?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 TestCommand extends ScheduledCommand {
/**
* The console command name.
*
* @var string
*/
protected $name = 'command:check';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Check if the meberships are verified.';
/**
* 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->everyMinutes(1);
}
/**
* Execute the console command.
*
* @return mixed
*/
public function fire()
{
Log::info('I was here @ ' . date('H:i:s'));
}
/**
* Get the console command arguments.
*
* @return array
*/
protected function getArguments()
{
return array(
// array('example', InputArgument::REQUIRED, 'An example argument.'),
);
}
/**
* Get the console command options.
*
* @return array
*/
protected function getOptions()
{
return array(
// array('example', null, InputOption::VALUE_OPTIONAL, 'An example option.', null),
);
}
}
So basically, I'm just writing a line in my log file (i.e. Storage/laravel.log) every time the scheduler is run. When I do php artisan scheduled:run
on my local machine, it writes a new line in my log file.
Now, I've uploaded the code on my server and have created a Cron job as:
The Cron job is running every minute as expected and the log file is also being updated every minute, but instead of the message I am writing in log file, its writing following error every minute:
[2016-09-24 09:20:01] production.ERROR: exception 'InvalidArgumentException' with message 'Command "command:check" is not defined.
Did you mean this?
command:make' in /home/mhjamil/public_html/l4-cron/test/vendor/symfony/console/Symfony/Component/Console/Application.php:564
Stack trace: #0 /home/mhjamil/public_html/l4-cron/test/vendor/symfony/console/Symfony/Component/Console/Application.php(190): Symfony\Component\Console\Application->find('command:check') #1 /home/mhjamil/public_html/l4-cron/test/vendor/symfony/console/Symfony/Component/Console/Application.php(124): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) #2 /home/mhjamil/public_html/l4-cron/test/artisan(58): Symfony\Component\Console\Application->run() #3 {main} [] []`
And by the way, I've registered the command in app/start/artisan.php as
Artisan::add(new TestCommand);
Also the command php artisan command:check
runs successfully on my local machine, but when I upload it to my server it says Command "command:check" is not defined.
And one more thing, on my server I have added a route and did Artican::call("command:check");
. Now whenever I reload this page, it logs an entry successfully in the log file. But its giving error when done through cron job. So I am guessing the problem is somewhat related to cron job or server settings.
I have tried changing cron command to:
/usr/bin/php /home/mhjamil/public_html/l4-cron/test/artisan command:check 1>> /dev/null 2>&1
previously I was using schaduled:run
but still same issue :(