/** * Execute the console command. * * @return void */ public function fire() { // Fire event before the Cron jobs will be executed \Event::fire('cron.collectJobs'); $report = Cron::run(); if ($report['inTime'] === -1) { $inTime = -1; } else { if ($report['inTime']) { $inTime = 'true'; } else { $inTime = 'false'; } } // Get Laravel version $laravel = app(); $version = $laravel::VERSION; if ($version < '5.2') { // Create table for old Laravel versions. $table = $this->getHelperSet()->get('table'); $table->setHeaders(array('Run date', 'In time', 'Run time', 'Errors', 'Jobs')); $table->addRow(array($report['rundate'], $inTime, round($report['runtime'], 4), $report['errors'], count($report['crons']))); } else { // Create table for new Laravel versions. $table = new \Symfony\Component\Console\Helper\Table($this->getOutput()); $table->setHeaders(array('Run date', 'In time', 'Run time', 'Errors', 'Jobs'))->setRows(array(array($report['rundate'], $inTime, round($report['runtime'], 4), $report['errors'], count($report['crons'])))); } // Output table. $table->render($this->getOutput()); }
/** * Execute the console command. * * @return void */ public function fire() { // Get the current timestamp and fire the collect event $runDate = new \DateTime(); \Event::fire('cron.collectJobs', array($runDate->getTimestamp())); // Get all registered Cron jobs $jobs = Cron::getCronJobs(); // Get Laravel version $laravel = app(); $version = $laravel::VERSION; if ($version < '5.2') { // Create the table helper with headers. $table = $this->getHelperSet()->get('table'); $table->setHeaders(array('Jobname', 'Expression', 'Activated')); // Run through all registered jobs for ($i = 0; $i < count($jobs); $i++) { // Get current job entry $job = $jobs[$i]; // If job is enabled or disable use the defined string instead of 1 or 0 $enabled = $job['enabled'] ? 'Enabled' : 'Disabled'; // Add this job to the table. $table->addRow(array($job['name'], $job['expression']->getExpression(), $enabled)); } } else { // Create table for new Laravel versions. $table = new \Symfony\Component\Console\Helper\Table($this->getOutput()); $table->setHeaders(array('Jobname', 'Expression', 'Activated')); $rows = []; // Run through all registered jobs for ($i = 0; $i < count($jobs); $i++) { // Get current job entry $job = $jobs[$i]; // If job is enabled or disable use the defined string instead of 1 or 0 $enabled = $job['enabled'] ? 'Enabled' : 'Disabled'; array_push($rows, array($job['name'], $job['expression']->getExpression(), $enabled)); } $table->setRows($rows); } // Render and output the table. $table->render($this->getOutput()); }
/** * Execute the console command. * * @return void */ public function fire() { // Fire event before the Cron jobs will be executed \Event::fire('cron.collectJobs'); $report = Cron::run(); if ($report['inTime'] === -1) { $inTime = -1; } else { if ($report['inTime']) { $inTime = 'true'; } else { $inTime = 'false'; } } // Create table. $table = $this->getHelperSet()->get('table'); $table->setHeaders(array('Run date', 'In time', 'Run time', 'Errors', 'Jobs')); $table->addRow(array($report['rundate'], $inTime, round($report['runtime'], 4), $report['errors'], count($report['crons']))); // Output table. $table->render($this->getOutput()); }
/** * Execute the console command. * * @return void */ public function fire() { // Get the current timestamp and fire the collect event $runDate = new \DateTime(); \Event::fire('cron.collectJobs', array($runDate->getTimestamp())); // Get all registered Cron jobs $jobs = Cron::getCronJobs(); // Create the table helper with headers. $table = $this->getHelperSet()->get('table'); $table->setHeaders(array('Jobname', 'Expression', 'Activated')); // Run through all registered jobs for ($i = 0; $i < count($jobs); $i++) { // Get current job entry $job = $jobs[$i]; // If job is enabled or disable use the defined string instead of 1 or 0 $enabled = $job['enabled'] ? 'Enabled' : 'Disabled'; // Add this job to the table. $table->addRow(array($job['name'], $job['expression']->getExpression(), $enabled)); } // Render and output the table. $table->render($this->getOutput()); }
/** * Test method for activating and deactivating the logging of all jobs to * Database and testing with full namespace declaration * * @covers \Liebig\Cron\Cron::setLogOnlyErrorJobsToDatabase */ public function testLogAllJobsToDatabaseWithFullNamespaceDeclaration() { $i = 0; \Liebig\Cron\Cron::add('test1', '* * * * *', function () use(&$i) { $i++; return null; }); \Liebig\Cron\Cron::add('test2', '* * * * *', function () use(&$i) { $i++; return true; }); \Liebig\Cron\Cron::add('test3', '* * * * *', function () use(&$i) { $i++; return false; }); \Liebig\Cron\Cron::add('test4', '* * * * *', function () use(&$i) { $i++; return null; }); \Liebig\Cron\Cron::setLogOnlyErrorJobsToDatabase(false); \Liebig\Cron\Cron::run(); $this->assertEquals(4, $i); $jobs = \Liebig\Cron\Models\Job::all(); $this->assertEquals(4, count($jobs)); $this->assertEquals('test1', $jobs[0]->name); $this->assertEquals('', $jobs[0]->return); $this->assertEquals('test2', $jobs[1]->name); $this->assertEquals('true', $jobs[1]->return); $this->assertEquals('test3', $jobs[2]->name); $this->assertEquals('false', $jobs[2]->return); $this->assertEquals('test4', $jobs[3]->name); $this->assertEquals('', $jobs[3]->return); \Liebig\Cron\Cron::setLogOnlyErrorJobsToDatabase(true); \Liebig\Cron\Cron::run(); $this->assertEquals(8, $i); $jobs2 = \Liebig\Cron\Models\Job::all(); $this->assertEquals(6, count($jobs2)); $this->assertEquals('test2', $jobs2[4]->name); $this->assertEquals('true', $jobs2[4]->return); $this->assertEquals('test3', $jobs2[5]->name); $this->assertEquals('false', $jobs2[5]->return); }