liebig / cron Goto Github PK
View Code? Open in Web Editor NEWJob scheduling for Laravel
License: Other
Job scheduling for Laravel
License: Other
I am able to execute the command in Terminal like this:
php artisan doSomething
Is the followings correct to execute the command within the cron?
This is my global.php:
Event::listen('cron.collectJobs', function() {
Cron::add('doSomething', '* * * * *', function() {
// Run every minute
Artisan::call('doSomething');
return null;
});
});
But php artisan cron:run always return -1:
+------------+---------+----------+--------+------+
| Run date | In time | Run time | Errors | Jobs |
+------------+---------+----------+--------+------+
| 1402831170 | -1 | -1 | 0 | 0 |
+------------+---------+----------+--------+------+
I've noticed that the result is truncated to 500 bytes when saved to cron_job.
I'm using a json_encoded result to indicate successful execution of the tasks, together with additional information about the execution, and often this can be longer than 500 bytes when json encoded; so the result written to the log is invalid json.
As the field is defined as text, and so would permit much longer data volumes to be stored, is it possible to make this a configurable option: either to disable the truncation, and/or to configure the size at which the result is truncated.
I'll happily submit a PR if you're open to the idea
Hi, We are having some issues with database temporarily gone away which causes the cron job to crash and leaves the cron.lock
file there forever. We have disabled the old logging rotation script that causes the database to be offline, but in case if the database might go away temporarily because of other reasons, what's the best way to prevent the cron.lock
file from being left forever?
Here is the stack trace if that's relevant:
Sep 26 03:05:05 LT-WEB8 Laravel: [2014-09-26 03:05:04] NULL.ERROR: exception 'ErrorException' with message 'PDO::__construct(): MySQL server has gone away' in D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:47
Sep 26 03:05:05 LT-WEB8 Laravel: Stack trace:
Sep 26 03:05:05 LT-WEB8 Laravel: #0 [internal function]: Illuminate\Exception\Handler->handleError(2, 'PDO::__construc...', 'D:\web\emcl\pas...', 47, Array)
Sep 26 03:05:05 LT-WEB8 Laravel: #1 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php(47): PDO->__construct('mysql:host=sql....', '', Array)
Sep 26 03:05:05 LT-WEB8 Laravel: #2 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Database\Connectors\MySqlConnector.php(20): Illuminate\Database\Connectors\Connector->createConnection('mysql:host=sql....', Array, Array)
Sep 26 03:05:05 LT-WEB8 Laravel: #3 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Database\Connectors\ConnectionFactory.php(59): Illuminate\Database\Connectors\MySqlConnector->connect(Array)
Sep 26 03:05:05 LT-WEB8 Laravel: #4 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Database\Connectors\ConnectionFactory.php(47): Illuminate\Database\Connectors\ConnectionFactory->createSingleConnection(Array)
Sep 26 03:05:05 LT-WEB8 Laravel: #5 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Database\DatabaseManager.php(127): Illuminate\Database\Connectors\ConnectionFactory->make(Array, 'emcl')
Sep 26 03:05:05 LT-WEB8 Laravel: #6 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Database\DatabaseManager.php(63): Illuminate\Database\DatabaseManager->makeConnection('emcl')
Sep 26 03:05:05 LT-WEB8 Laravel: #7 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php(2810): Illuminate\Database\DatabaseManager->connection(NULL)
Sep 26 03:05:05 LT-WEB8 Laravel: #8 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php(2776): Illuminate\Database\Eloquent\Model::resolveConnection(NULL)
Sep 26 03:05:05 LT-WEB8 Laravel: #9 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php(1791): Illuminate\Database\Eloquent\Model->getConnection()
Sep 26 03:05:05 LT-WEB8 Laravel: #10 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php(1714): Illuminate\Database\Eloquent\Model->newBaseQueryBuilder()
Sep 26 03:05:05 LT-WEB8 Laravel: #11 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php(2999): Illuminate\Database\Eloquent\Model->newQuery()
Sep 26 03:05:05 LT-WEB8 Laravel: #12 [internal function]: Illuminate\Database\Eloquent\Model->__call('orderBy', Array)
Sep 26 03:05:05 LT-WEB8 Laravel: #13 [internal function]: Liebig\Cron\Models\Manager->orderBy('rundate', 'DESC')
Sep 26 03:05:05 LT-WEB8 Laravel: #14 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php(3015): call_user_func_array(Array, Array)
Sep 26 03:05:05 LT-WEB8 Laravel: #15 D:\web\emcl\passport\builds\api\291\vendor\liebig\cron\src\Liebig\Cron\Cron.php(188): Illuminate\Database\Eloquent\Model::__callStatic('orderBy', Array)
Sep 26 03:05:05 LT-WEB8 Laravel: #16 D:\web\emcl\passport\builds\api\291\vendor\liebig\cron\src\Liebig\Cron\Cron.php(188): Liebig\Cron\Models\Manager::orderBy('rundate', 'DESC')
Sep 26 03:05:05 LT-WEB8 Laravel: #17 D:\web\emcl\passport\builds\api\291\vendor\liebig\cron\src\Liebig\Cron\RunCommand.php(40): Liebig\Cron\Cron::run()
Sep 26 03:05:05 LT-WEB8 Laravel: #18 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Console\Command.php(108): Liebig\Cron\RunCommand->fire()
Sep 26 03:05:05 LT-WEB8 Laravel: #19 D:\web\emcl\passport\builds\api\291\vendor\symfony\console\Symfony\Component\Console\Command\Command.php(241): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArrayInput), Object(Symfony\Component\Console\Output\NullOutput))
Sep 26 03:05:05 LT-WEB8 Laravel: #20 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Console\Command.php(96): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArrayInput), Object(Symfony\Component\Console\Output\NullOutput))
Sep 26 03:05:05 LT-WEB8 Laravel: #21 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Console\Application.php(96): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArrayInput), Object(Symfony\Component\Console\Output\NullOutput))
Sep 26 03:05:05 LT-WEB8 Laravel: #22 [internal function]: Illuminate\Console\Application->call('cron:run', Array)
Sep 26 03:05:05 LT-WEB8 Laravel: #23 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Foundation\Artisan.php(57): call_user_func_array(Array, Array)
Sep 26 03:05:05 LT-WEB8 Laravel: #24 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php(211): Illuminate\Foundation\Artisan->__call('call', Array)
Sep 26 03:05:05 LT-WEB8 Laravel: #25 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php(211): Illuminate\Foundation\Artisan->call('cron:run', Array)
Sep 26 03:05:05 LT-WEB8 Laravel: #26 D:\web\emcl\passport\builds\api\291\vendor\liebig\cron\src\Liebig\Cron\CronServiceProvider.php(46): Illuminate\Support\Facades\Facade::__callStatic('call', Array)
Sep 26 03:05:05 LT-WEB8 Laravel: #27 D:\web\emcl\passport\builds\api\291\vendor\liebig\cron\src\Liebig\Cron\CronServiceProvider.php(46): Illuminate\Support\Facades\Artisan::call('cron:run', Array)
Sep 26 03:05:05 LT-WEB8 Laravel: #28 [internal function]: Liebig\Cron\CronServiceProvider->Liebig\Cron\{closure}()
Sep 26 03:05:05 LT-WEB8 Laravel: #29 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Routing\Route.php(105): call_user_func_array(Object(Closure), Array)
Sep 26 03:05:05 LT-WEB8 Laravel: #30 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Routing\Router.php(1000): Illuminate\Routing\Route->run(Object(Illuminate\Http\Request))
Sep 26 03:05:05 LT-WEB8 Laravel: #31 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Routing\Router.php(968): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))
Sep 26 03:05:05 LT-WEB8 Laravel: #32 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(738): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
Sep 26 03:05:05 LT-WEB8 Laravel: #33 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(708): Illuminate\Foundation\Application->dispatch(Object(Illuminate\Http\Request))
Sep 26 03:05:05 LT-WEB8 Laravel: #34 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Http\FrameGuard.php(38): Illuminate\Foundation\Application->handle(Object(Illuminate\Http\Request), 1, true)
Sep 26 03:05:05 LT-WEB8 Laravel: #35 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Session\Middleware.php(72): Illuminate\Http\FrameGuard->handle(Object(Illuminate\Http\Request), 1, true)
Sep 26 03:05:05 LT-WEB8 Laravel: #36 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Cookie\Queue.php(47): Illuminate\Session\Middleware->handle(Object(Illuminate\Http\Request), 1, true)
Sep 26 03:05:05 LT-WEB8 Laravel: #37 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Cookie\Guard.php(51): Illuminate\Cookie\Queue->handle(Object(Illuminate\Http\Request), 1, true)
Sep 26 03:05:05 LT-WEB8 Laravel: #38 D:\web\emcl\passport\builds\api\291\vendor\stack\builder\src\Stack\StackedHttpKernel.php(23): Illuminate\Cookie\Guard->handle(Object(Illuminate\Http\Request), 1, true)
Sep 26 03:05:05 LT-WEB8 Laravel: #39 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(606): Stack\StackedHttpKernel->handle(Object(Illuminate\Http\Request))
Sep 26 03:05:05 LT-WEB8 Laravel: #40 D:\web\emcl\passport\builds\api\291\public\index.php(49): Illuminate\Foundation\Application->run()
Sep 26 03:05:05 LT-WEB8 Laravel: #41 {main}
Sep 26 03:05:05 LT-WEB8 Laravel: Next exception 'PDOException' with message 'SQLSTATE[HY000] [2006] MySQL server has gone away' in D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:47
Sep 26 03:05:05 LT-WEB8 Laravel: Stack trace:
Sep 26 03:05:05 LT-WEB8 Laravel: #0 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php(0): PDO->__construct()
Sep 26 03:05:05 LT-WEB8 Laravel: #1 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Database\Connectors\MySqlConnector.php(20): Illuminate\Database\Connectors\Connector->createConnection('mysql:host=sql....', Array, Array)
Sep 26 03:05:05 LT-WEB8 Laravel: #2 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Database\Connectors\ConnectionFactory.php(59): Illuminate\Database\Connectors\MySqlConnector->connect(Array)
Sep 26 03:05:05 LT-WEB8 Laravel: #3 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Database\Connectors\ConnectionFactory.php(47): Illuminate\Database\Connectors\ConnectionFactory->createSingleConnection(Array)
Sep 26 03:05:05 LT-WEB8 Laravel: #4 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Database\DatabaseManager.php(127): Illuminate\Database\Connectors\ConnectionFactory->make(Array, 'emcl')
Sep 26 03:05:05 LT-WEB8 Laravel: #5 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Database\DatabaseManager.php(63): Illuminate\Database\DatabaseManager->makeConnection('emcl')
Sep 26 03:05:05 LT-WEB8 Laravel: #6 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php(2810): Illuminate\Database\DatabaseManager->connection(NULL)
Sep 26 03:05:05 LT-WEB8 Laravel: #7 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php(2776): Illuminate\Database\Eloquent\Model::resolveConnection(NULL)
Sep 26 03:05:05 LT-WEB8 Laravel: #8 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php(1791): Illuminate\Database\Eloquent\Model->getConnection()
Sep 26 03:05:05 LT-WEB8 Laravel: #9 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php(1714): Illuminate\Database\Eloquent\Model->newBaseQueryBuilder()
Sep 26 03:05:05 LT-WEB8 Laravel: #10 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php(2999): Illuminate\Database\Eloquent\Model->newQuery()
Sep 26 03:05:05 LT-WEB8 Laravel: #11 [internal function]: Illuminate\Database\Eloquent\Model->__call('orderBy', Array)
Sep 26 03:05:05 LT-WEB8 Laravel: #12 [internal function]: Liebig\Cron\Models\Manager->orderBy('rundate', 'DESC')
Sep 26 03:05:05 LT-WEB8 Laravel: #13 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php(3015): call_user_func_array(Array, Array)
Sep 26 03:05:05 LT-WEB8 Laravel: #14 D:\web\emcl\passport\builds\api\291\vendor\liebig\cron\src\Liebig\Cron\Cron.php(188): Illuminate\Database\Eloquent\Model::__callStatic('orderBy', Array)
Sep 26 03:05:05 LT-WEB8 Laravel: #15 D:\web\emcl\passport\builds\api\291\vendor\liebig\cron\src\Liebig\Cron\Cron.php(188): Liebig\Cron\Models\Manager::orderBy('rundate', 'DESC')
Sep 26 03:05:05 LT-WEB8 Laravel: #16 D:\web\emcl\passport\builds\api\291\vendor\liebig\cron\src\Liebig\Cron\RunCommand.php(40): Liebig\Cron\Cron::run()
Sep 26 03:05:05 LT-WEB8 Laravel: #17 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Console\Command.php(108): Liebig\Cron\RunCommand->fire()
Sep 26 03:05:05 LT-WEB8 Laravel: #18 D:\web\emcl\passport\builds\api\291\vendor\symfony\console\Symfony\Component\Console\Command\Command.php(241): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArrayInput), Object(Symfony\Component\Console\Output\NullOutput))
Sep 26 03:05:05 LT-WEB8 Laravel: #19 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Console\Command.php(96): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArrayInput), Object(Symfony\Component\Console\Output\NullOutput))
Sep 26 03:05:05 LT-WEB8 Laravel: #20 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Console\Application.php(96): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArrayInput), Object(Symfony\Component\Console\Output\NullOutput))
Sep 26 03:05:05 LT-WEB8 Laravel: #21 [internal function]: Illuminate\Console\Application->call('cron:run', Array)
Sep 26 03:05:05 LT-WEB8 Laravel: #22 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Foundation\Artisan.php(57): call_user_func_array(Array, Array)
Sep 26 03:05:05 LT-WEB8 Laravel: #23 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php(211): Illuminate\Foundation\Artisan->__call('call', Array)
Sep 26 03:05:05 LT-WEB8 Laravel: #24 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php(211): Illuminate\Foundation\Artisan->call('cron:run', Array)
Sep 26 03:05:05 LT-WEB8 Laravel: #25 D:\web\emcl\passport\builds\api\291\vendor\liebig\cron\src\Liebig\Cron\CronServiceProvider.php(46): Illuminate\Support\Facades\Facade::__callStatic('call', Array)
Sep 26 03:05:05 LT-WEB8 Laravel: #26 D:\web\emcl\passport\builds\api\291\vendor\liebig\cron\src\Liebig\Cron\CronServiceProvider.php(46): Illuminate\Support\Facades\Artisan::call('cron:run', Array)
Sep 26 03:05:05 LT-WEB8 Laravel: #27 [internal function]: Liebig\Cron\CronServiceProvider->Liebig\Cron\{closure}()
Sep 26 03:05:05 LT-WEB8 Laravel: #28 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Routing\Route.php(105): call_user_func_array(Object(Closure), Array)
Sep 26 03:05:05 LT-WEB8 Laravel: #29 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Routing\Router.php(1000): Illuminate\Routing\Route->run(Object(Illuminate\Http\Request))
Sep 26 03:05:05 LT-WEB8 Laravel: #30 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Routing\Router.php(968): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))
Sep 26 03:05:05 LT-WEB8 Laravel: #31 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(738): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
Sep 26 03:05:05 LT-WEB8 Laravel: #32 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(708): Illuminate\Foundation\Application->dispatch(Object(Illuminate\Http\Request))
Sep 26 03:05:05 LT-WEB8 Laravel: #33 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Http\FrameGuard.php(38): Illuminate\Foundation\Application->handle(Object(Illuminate\Http\Request), 1, true)
Sep 26 03:05:05 LT-WEB8 Laravel: #34 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Session\Middleware.php(72): Illuminate\Http\FrameGuard->handle(Object(Illuminate\Http\Request), 1, true)
Sep 26 03:05:05 LT-WEB8 Laravel: #35 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Cookie\Queue.php(47): Illuminate\Session\Middleware->handle(Object(Illuminate\Http\Request), 1, true)
Sep 26 03:05:05 LT-WEB8 Laravel: #36 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Cookie\Guard.php(51): Illuminate\Cookie\Queue->handle(Object(Illuminate\Http\Request), 1, true)
Sep 26 03:05:05 LT-WEB8 Laravel: #37 D:\web\emcl\passport\builds\api\291\vendor\stack\builder\src\Stack\StackedHttpKernel.php(23): Illuminate\Cookie\Guard->handle(Object(Illuminate\Http\Request), 1, true)
Sep 26 03:05:05 LT-WEB8 Laravel: #38 D:\web\emcl\passport\builds\api\291\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(606): Stack\StackedHttpKernel->handle(Object(Illuminate\Http\Request))
Sep 26 03:05:05 LT-WEB8 Laravel: #39 D:\web\emcl\passport\builds\api\291\public\index.php(49): Illuminate\Foundation\Application->run()
Sep 26 03:05:05 LT-WEB8 Laravel: #40 {main} [] []
Hi,
I am using crontab to execute the artisan cron:run command every minute and did not want the cron_manager table being logged to but I did want job errors logged to the cron_job table so I thought having my config.php configured as follows would solve that:
'databaseLogging' => true,
'logOnlyErrorJobsToDatabase' => true,
This didn't work as expected because the cron_manager table continued to still get updated every minute. The only way I could get cron to stop logging to the cron_manager table was to change the configuration to:
'databaseLogging' => false,
Which then stopped my result from getting logged to the cron_job table. Is this the way the feature is suppossed to work? I would expect that if logOnlyErrorJobsToDatabase is set to true then the cron_manager and cron_job tables would only get updated when an error occurred.
Thanks in advance,
Troy Carpenter
Follow-up of #20
The package should provide a route that calls Artisan::call('cron:run')
. This should of course have some form of protection to prevent anyone from accessing the URL inadvertently, potentially causing issues. So my idea is that there should be an automatically generated security token, which will be saved to a configuration file.
A few things to consider (hey, I don't have all the answers):
php artisan config:publish liebig/cron
?Hello,
i have a controller from which i connect to an sql server and i get some results.
Where i run the function using the web interface, the function runs with no problem.
my controller:
class ProductController extends \BaseController {
public function __construct(Setting $setting, SqlServer $sqlserver, Opencart $opencart)
{
$this->setting = $setting;
$this->sqlserver = $sqlserver;
$this->connectionOC = 'localOC';
}
public function addNewProducts() {
$opencart = $this->connectionOC;
$t = $this->setting->getLastProductTimestamp();
$products = $this->sqlserver->getSeries();
return $products;
}
}
The cron:
Event::listen('cron.collectJobs', function() {
Cron::add('AddNewProducts', '* * * * *', function() {
$pr = App::make('ProductController')->addNewProducts();
});
});
If run php artisan cron:run and i get in db log "Exception in job AddNewProducts: could not find driver".
I have tested the previous connection eg. $this->setting->getLast..... and it works.
The error comes drom sqlserver connection, it seems that it cannot find the driver which is already set and working all over the other application.
What am i doing wrong?
Thanks
-Konstantinos
Class 'Liebig\Cron\models\Manager' not found
if (self::isDatabaseLogging()) {
// Get the time (in seconds) between this and the last run and save this to $timeBetween
$lastManager = \Liebig\Cron\models\Manager::orderBy('rundate', 'DESC')->take(1)->get();
if (!empty($lastManager[0])) {
$lastRun = new \DateTime($lastManager[0]->rundate);
I have this configuration
1 - cronjob (every 1 hour)
2 - cronjob( everny 10 minutes)
if the 1 cronjob takes 30minutes to run, the second is going to be executed in this period 3 time's or not because is locked ?
I have create a cron job run every 2 minutes
Cron::add('collect', '*/2 * * * *', function() {
// code to insert database to table test
});
When I run cmd php artisan cron:run
first time, it insert record into table cron_job and cron_manager and not insert record to table test.
I wait more 2 minutes and run cron again but it not insert into table test. I don't know why?
Log file content is:
[2014-12-02 17:27:56] production.ERROR: Cron run with manager id 2 is with 227 seconds between last run too late. [] []
[2014-12-02 17:27:56] production.INFO: The cron run with the manager id 2 was finished without errors. [] []
Class 'Liebig\Cron\Facades\Cron' not found
Ubuntu 13.04
PHP 5.4.9
Laravel 4.1
Fresh install of Laravel, and isntalled Cron following your install instructions in Readme
Hi Liebig,
Some of the jobs I schedule never get executed.
For example, a job with expression '25 11 * * 4' which should execute each Thursday at 11:25 is skipped (cron manager does execute fine). It seems to me that the isDue function is not parsing my expression correctly so it is never matched?
Any help would be greatly appreciated.
Thanks for this awesome package!
Hi,
this is not really an issue, but rather some help I need that I couldn't find in the documentation.
I'm missing info on how to use this on windows.
using git bash and typing in the url rout (http: //localhost:800/cron/run/key) my command runs correctly. Now the cron (setup to run automaticlly) is giving me problems.
is it possible to run on windows and what are my next steps? I rather not use the windows task manager to run a batch file.
Note1: from the git bash in the root folder I ran ' * * * * * php artisan cron:run ' but get an error (it reads ./contributing.md from the root folder), so I'm doing something wrong there
Note2: running ' php artisan cron:list ' I get an emtpy list (table)
Hi Liebig,
I have an issue with cron. Installed according to your description without any problem.
I have basic Laravel application with Auth users and Route controller in context root:
Route::controller('/', 'UsersController');
When I'm trying to run my cron:
http://mydomain.com/cron.php?key=mykey
I'm getting "Controller method not found" exception.
Don't you know where the problem could be? Are Laravel's controllers executed before your
\Route::get('cron.php', function() {
code?
Where must I have put folder src and tests?
When I run "composer update liebig/cron --no-dev" return the error
Problem 1
Protential causes:
Read http://getcomposer.org/doc/articles/troubleshooting.md for further common
roblems.
Please help me. Thanks!
Iam using your example code in global.php
Event::listen('cron.collectJobs', function() {
Cron::add('send email', '* * * * *', function() {
mail('[email protected]', 'My Subject', 'message');
return null;
});
Cron::add('disabled job', '0 * * * *', function() {
// Do some crazy things successfully every hour
}, false);
});
And when I do http:root/cron.php?key=$key
only Once cron job will execute and table also get updated once.How to execute this function every minute ?
Hey,
$ * * * * * /usr/bin/php $HOME/Documents/etm/api/artisan cron:run
gives me
zsh: command not found: app
Maybe, zsh is the culprit here?
edit1: same with bash
$ * * * * * /usr/bin/php $HOME/Documents/etm/api/artisan cron:run
No command 'app' found, but there are 17 similar ones
app: command not found
edit2: reading http://askubuntu.com/questions/23009/reasons-why-crontab-does-not-work
edit3: just going to use external service...
my project is developed base on oracle database, Is the program support oracle?
hi ...
I after add new cron , played it ...
But only once the function is executed ...
i use full example in readme ...
What should I do to make this cron will continue ?
I tried that, but it does not work:
Event::listen('cron.collectJobs', function() {
Cron::add('parseEvents', '0 0-23 * * *', function() {
Log::info('test');
});
});
in app/start/global.php
I've installed and condigured it in my Laravel 4 app. Now i want to run added tasks in a given period. What should i do to make this commad run automaticly? i mean what software or CLI to use? I'm using windows and want to run tasks locally.
Hi!
I'm not sure if this could be an issue but I cannot find any information about it, neither on the apache-php nor the laravel forums.
I'm running a job using your bundle and it takes about 5-6 seconds to complete. This job is just a loop of about 20 requests of an URI which returns a simple json response each time is called. Then I parse every response in turn.
Well, the problem is that while this job is running I can't make any concurrent request to any page of my laravel-based site. Actually, I can make the request but
I have to wait until the job has finished to get a response to the concurrent request.
I have tested in different environments (dev, production) and servers (apache, laravel built-in server) and the problem remains the same.
Thank you for any information or direction you can provide.
php artisan migrate --package="Liebig/Cron"
should be
php artisan migrate --package="liebig/cron"
When i run http://site.local/cron.php?key=doLTy3JDyi0xRpTR2qN i get error:
[2014-11-26 10:20:55] local.ERROR: exception 'BadMethodCallException' with message 'Call to undefined method Illuminate\Database\Query\Builder::fire()' in /Users/mezhevikin/Desktop/rnd.local/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:2113
I create a test cron every minute
Event::listen('cron.collectJobs', function() {
Cron::add('test', '* * * * *', function() {
Log::info('test');
});
});
When I open my website and it will auto run cron every minute, right?
Must do I do anything more to do that? Ex: run cron by cmd: php artisan cron:run
Cron::add('testcron', '*/5 * * * *', function() {
return null;
}, true);
Cron::setEnableJob('testcron');
print_r(Cron::run());
Nothings added to the cron_jobs table, did I do something wrong?
Hi,
Is there a way using cron.afterRun and $inTime to check for a job not being run when it was supposed to? For example, I have the a job that gets added in a cron.collectJobs listener that is supposed to run everyday at a certain time and it just so happens that server reboot was required or maybe Laravel was down at that time. Would it be possible to detect that the cron job was not executed in the cron.afterRun so that I can execute the command that was supposed to be previously executed? If so, could you show a code example?
Thanks in advance,
Troy
Hi,
My liebig cron jobs are no longer running and I have not changed any settings on my server. The issue seemingly started to occur shortly after I did a composer update for this 3-4 weeks back. I am currently getting the following logged to the laravel log:
dev.WARNING: Lock file found - Cron is still running and prevent job overlapping is enabled - second Cron run will be terminated.
Any ideas on what is causing this and how I can fix it? Which lock file is being referenced here?
Thanks,
Troy
I would like to use this package for a site which will run on multiple ec2 instances of amazon web services behind a load balancer. Now I see two options:
What do you think? What is the way to go?
Is it possible to move the run() into a command instead of using a route? Then just fire that on the cronjob using php artisan command instead of using wget?
I haven't installed this yet to try.
Thanks.
I try to run cronjob like this
Event::listen('cron.collectJobs', function() {
Cron::add('example1', '* * * * *', function() {
// Do some crazy things unsuccessfully every minute
return 'No';
});
});
and I set my crontab like this
* * * * * /usr/bin/php /var/www/mylaravel/artisan cron:run
and wait about 1 min
the cron_manager have a value
1 2014-08-13 21:27:03 -1.00
2 2014-08-13 21:28:03 -1.00
3 2014-08-13 21:29:03 -1.00
4 2014-08-13 21:30:03 -1.00
5 2014-08-13 21:31:03 -1.00
6 2014-08-13 21:32:03 -1.00
7 2014-08-13 21:33:03 -1.00
but the cron_job no value
I expect it has a value "NO" on return column
What I do wrong?
Hi,
I don't understand why the cron.lock is not deleted sometimes without errors, is there a way to raise the "Lock file found" event so I can send me a mail to check what's is wrong ?
Thanks,
Pierre.
Is it possible to pass a variable to Cron::add function?
$variable = 'testing';
Cron::add('example', '* * * * *', function($variable) {
Log::info($variable);
return null;
}
The last release (v0.9.5) is from February and it doesn't include several important bits, like RunCommand
.
Can you please tag a new release so those of use who don't want to use dev-master
can update?
Also the v
in the version is preventing us from using "liebig/cron": "0.9.*"
as "liebig/cron": "v0.9.*"
is not allowed in composer. So maybe you could start tagging releases without the v
?
I'm on Eastern US time, the server is set to ET, but the jobs are running 5 hours out of whack.
It appears the library uses the timestamp which is based off UTC time.
Is there a way to make it respect the timezone of the system it's on?
hi
I use liebig/cron
it worked good this morning.
but now not working
--this situation
+----------+------------+-----------+
| Jobname | Expression | Activated |
+----------+------------+-----------+
| example1 | * * * * * | Enabled |
| example3 | * * * * * | Enabled |
| example2 | 28 * * * * | Enabled |
+----------+------------+-----------+
but
+------------+---------+----------+--------+------+
| Run date | In time | Run time | Errors | Jobs |
+------------+---------+----------+--------+------+
| 1409020245 | -1 | -1 | 0 | 0 |
+------------+---------+----------+--------+------+
always keep to occur
help me please
In step 4 of the installation process, I get an error (below) when trying to run the Artisan migration:
Digging around, I've found a discussion on the Laracasts forums where it's pointed out this could be related to the new structure of Laravel 5.
Anybody has any idea about this?
exception 'BadMethodCallException' with message 'Call to undefined method [package]' in /home/vagrant/myApplication/vendor/laravel/framework/src/Illuminate/Support/ServiceProvider.php:226
Stack trace:
#0 /home/vagrant/myApplication/vendor/liebig/cron/src/Liebig/Cron/CronServiceProvider.php(22): Illuminate\Support\ServiceProvider->__call('package', Array)
#1 /home/vagrant/myApplication/vendor/liebig/cron/src/Liebig/Cron/CronServiceProvider.php(22): Liebig\Cron\CronServiceProvider->package('liebig/cron')
#2 [internal function]: Liebig\Cron\CronServiceProvider->boot()
#3 /home/vagrant/myApplication/vendor/laravel/framework/src/Illuminate/Container/Container.php(523): call_user_func_array(Array, Array)
#4 /home/vagrant/myApplication/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(631): Illuminate\Container\Container->call(Array)
#5 /home/vagrant/myApplication/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(613): Illuminate\Foundation\Application->bootProvider(Object(Liebig\Cron\CronServiceProvider))
#6 [internal function]: Illuminate\Foundation\Application->Illuminate\Foundation\{closure}(Object(Liebig\Cron\CronServiceProvider), 19)
#7 /home/vagrant/myApplication/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(614): array_walk(Array, Object(Closure))
#8 /home/vagrant/myApplication/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/BootProviders.php(15): Illuminate\Foundation\Application->boot()
#9 /home/vagrant/myApplication/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(165): Illuminate\Foundation\Bootstrap\BootProviders->bootstrap(Object(Illuminate\Foundation\Application))
#10 /home/vagrant/myApplication/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(192): Illuminate\Foundation\Application->bootstrapWith(Array)
#11 /home/vagrant/myApplication/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(89): Illuminate\Foundation\Console\Kernel->bootstrap()
#12 /home/vagrant/myApplication/artisan(36): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#13 {main}
Hi @liebig , Here raise an exception after I upgrade my php from 5.4.9
to 5.5.15
today.
I did not change anything of my code, and I found that there raise an exception said Impossible CRON expression
in CronExpression.php
line at line 321
and cron.lock
created in storage path.
for example, all the follow will not work(Impossible CRON expression)
0 1 * * *
0 2 * * *
0 4 * * *
0 5 * * *
but the follow will work!
0 0 * * *
0 3 * * *
0 6 * * *
0 9 * * *
0 12 * * *
so strage issue. need your help!!!
How would you go about setting up cron jobs like example in cPanel?
Thanks
UPDATE "I figured it out you use wget thanks for the script. You can close this."
TIP "Just a suggestion you might look in to clarifying this a little more with a example or something or refer people to the below url."
http://stackoverflow.com/questions/13259530/using-cron-jobs-to-visit-url
I have a questions for this library, if I can use/get a server for call the request for the url, why I need this cron library? And this library also require a crontab or third party server to call the url. I am a kind of confuse..
i try to run cron in command "php artisan cron:run" but show me this error
"[ErrorException]
Undefined index: inTime"
can some one please explain me show can i run cron on my machine, i used windows ?
when i go to cron url path /cron/run/sdasdasdawq2323123 show me this message "Array ( [rundate] => 1400113159 [runtime] => -1 ) " is it error or what ?
* @static
* @param string $name The name for the cron job - has to be unique
* @param string $expression The cron job expression (e.g. for every minute: '* * * * *')
* @param function $function The anonymous function which will be executed
* @param bool $isEnabled optional If the cron job should be enabled or disabled - the standard configuration is enabled
* @throws InvalidArgumentException if one of the parameters has the wrong data type, is incorrect or is not set
*/
public static function add($name, $expression, $function, $isEnabled = true) {
please change the function
to Closure
, just like follow
* @static
* @param string $name The name for the cron job - has to be unique
* @param string $expression The cron job expression (e.g. for every minute: '* * * * *')
* @param Closure $function The anonymous function which will be executed
* @param bool $isEnabled optional If the cron job should be enabled or disabled - the standard configuration is enabled
* @throws InvalidArgumentException if one of the parameters has the wrong data type, is incorrect or is not set
*/
public static function add($name, $expression, $function, $isEnabled = true) {
It isn't clear to me where to put my cron definitions. I am writing a package that requires cron to do some pulling of data from a remote source. I defined a cron rule in my service provider's boot method, as that seems like the right place for it.
Apparently through, the facade for the "cron" class is added after my boot
method ran, which means I can only use it with the fully qualified class name. I could, however, get it working by editing CronServiceProvider.php
to directly add the facade in the register
method, like so:
$loader = \Illuminate\Foundation\AliasLoader::getInstance();
$loader->alias('Cron', 'Liebig\Cron\Facades\Cron');
Am I doing something wrong, should I put my definition somewhere else? Is the above suggestion flawed for some reason? Or should I just put the facade in my app.config
?
I found this resource, and feel it's helpful. Maybe it's better that you have that built in your stuff too.
https://gist.github.com/andergmartins/5066143
Hello,
I have a script checking errors on webpages. I'm trying to develop a tool with Laravel to manage 'alerts' (automated calls to this script to maintain a surveillance).
But I'm a bit confused about how to using your lib.
When I add a cron like this :
Route::get('/crontest', function() {
Cron::add('example1', '* * * * *', function() {
return 'Example 1 ran';
});
$report = \Liebig\Cron\Cron::run();
var_dump($report);
});
I get a new line in cron_manager like this :
| 719 | 2014-12-04 14:29:02 | 0.00 |
And a new line in cron_jobs like this :
| 11 | example1 | Example 1 ran | 0.00 | 719 |
But nothing else. As far as I understand, I should have a new line in cron_manager every minutes. But I don't.
Must I use Event::listen('cron.collectJobs') to add crons ? What does it concretely do ?
Can I call Cron::add everywhere in the app ?
Sorry for my mistakes, English isn't my native language.
Thank you in advance.
I am beginner to the laravel 4 and cron queue. I want to use the cron queue to post the posts to facebook page in particular time . Can any one help ..?
Class 'Liebig\Cron\models\Manager' not found
if (self::isDatabaseLogging()) {
// Get the time (in seconds) between this and the last run and save this to $timeBetween
$lastManager = \Liebig\Cron\models\Manager::orderBy('rundate', 'DESC')->take(1)->get();
if (!empty($lastManager[0])) {
$lastRun = new \DateTime($lastManager[0]->rundate);
I read the Readme about 3 times and I have a bit confuse with how to start to cron my job.
So I have question about how to start and is I'm do the right thing ?
OK. I will start at if I want to update my database every 4 AM. and 5 AM.
1. I start at create a crontab -e
0 4 * * * /usr/bin/php /var/www/laravel/artisan cron:run
0 5 * * * /usr/bin/php /var/www/laravel/artisan cron:run
2. I start add a cron job on start/global.php
Event::listen('cron.collectJobs', function() {
Cron::add('example1', '0 4 * * *', function() {
// update my article table
// how can I call my controller and method ?
$newdata = ArticleController@addnewdata()
if ($newdata){
// if it update success return "yes"
return 'YES';
}
return 'NO';
});
Cron::add('example2', '0 5 * * *', function() {
// update my comment
// if it success return "YES"
return 'YES';
});
});
and my "YES" will show on liebig/cron table ?
Thank you verymuch.
Seems to be a weird conflict with generators.
if i uninstall generators it works fine. But i must have my generators!!! :)
php artisan migrate --package="liebig/cron"
PHP Fatal error: Class 'Way\Generators\GeneratorsServiceProvider' not found in /vagrant/www/lms/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php on line 158
PHP Stack trace:
PHP 1. {main}() /vagrant/www/lms/artisan:0
PHP 2. require_once() /vagrant/www/lms/artisan:30
PHP 3. require() /vagrant/www/lms/bootstrap/start.php:60
PHP 4. Illuminate\Foundation\ProviderRepository->load() /vagrant/www/lms/vendor/laravel/framework/src/Illuminate/Foundation/start.php:210
PHP 5. Illuminate\Foundation\ProviderRepository->compileManifest() /vagrant/www/lms/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php:58
PHP 6. Illuminate\Foundation\ProviderRepository->createProvider() /vagrant/www/lms/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php:122
{"error":{"type":"Symfony\Component\Debug\Exception\FatalErrorException","message":"Class 'Way\Generators\GeneratorsServiceProvider' not found","file":"/vagrant/www/lms/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php","line":158}}
The configuration file is named Config.php
, but Laravel uses config.php
when loading package-specific configuration files. This doesn't affect Windows users, but the configuration is completely ignored on Linux, and all settings default to falsey values (because Config::get('cron::setting')
returns null
, since it can't find the config file).
This also affects publishing, since artisan config:publish
just copies the file from the vendor folder as-is, so it will also be copied with the wrong name.
The solution is simple - just lowercase the filename.
I'll send a pull request for this in a couple of minutes.
Hello,thanks for your library for Cron in laravel.
i test for every minute for cron
and add crontab for every minute it's work fine.
but i wanna cron for midnight and change * * * * to 0 0 * * for my Cron and crontab and boom not work...
checked cron manager on database and see rundate time is 05:10:25 like that any idea?!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.