Skip to content
Code-Schnipsel Gruppen Projekte
Commit 7749ec86 erstellt von Henning Leutz's avatar Henning Leutz :martial_arts_uniform:
Dateien durchsuchen

Cron Console kann einzelne Crons per ID ausführen

Übergeordneter 3c6f60bd
No related branches found
No related tags found
Keine zugehörigen Merge Requests gefunden
...@@ -6,13 +6,14 @@ ...@@ -6,13 +6,14 @@
namespace QUI\Cron; namespace QUI\Cron;
use QUI;
/** /**
* Cron Console Manager * Cron Console Manager
* *
* @author www.namerobot.com (Henning Leutz) * @author www.namerobot.com (Henning Leutz)
*/ */
class Console extends QUI\System\Console\Tool
class Console extends \QUI\System\Console\Tool
{ {
/** /**
* Konstruktor * Konstruktor
...@@ -20,7 +21,7 @@ class Console extends \QUI\System\Console\Tool ...@@ -20,7 +21,7 @@ class Console extends \QUI\System\Console\Tool
public function __construct() public function __construct()
{ {
$this->setName('package:cron') $this->setName('package:cron')
->setDescription('Cron Manager'); ->setDescription('Cron Manager');
} }
/** /**
...@@ -30,25 +31,28 @@ class Console extends \QUI\System\Console\Tool ...@@ -30,25 +31,28 @@ class Console extends \QUI\System\Console\Tool
*/ */
public function execute() public function execute()
{ {
$run = $this->getArgument('--run'); $run = $this->getArgument('--run');
$list = $this->getArgument('--list'); $list = $this->getArgument('--list');
$listall = $this->getArgument('--list-all'); $listall = $this->getArgument('--list-all');
$runCron = $this->getArgument('--cron');
if ($run) { if ($run) {
$this->run(); $this->run();
return; return;
} }
if ($list) { if ($list) {
$this->listCrons(); $this->listCrons();
return; return;
} }
if ($listall) { if ($listall) {
$this->listAllCrons(); $this->listAllCrons();
return;
}
if ($runCron) {
$this->runCron($runCron);
return; return;
} }
...@@ -68,6 +72,7 @@ class Console extends \QUI\System\Console\Tool ...@@ -68,6 +72,7 @@ class Console extends \QUI\System\Console\Tool
$this->writeLn("- run\t\trun all active crons"); $this->writeLn("- run\t\trun all active crons");
$this->writeLn("- list\t\tlist all active crons"); $this->writeLn("- list\t\tlist all active crons");
$this->writeLn("- list-all\tlist all crons"); $this->writeLn("- list-all\tlist all crons");
$this->writeLn("- cron\trun a specific cron");
$this->writeLn(''); $this->writeLn('');
...@@ -93,9 +98,27 @@ class Console extends \QUI\System\Console\Tool ...@@ -93,9 +98,27 @@ class Console extends \QUI\System\Console\Tool
$this->commandRead(); $this->commandRead();
break; break;
case 'cron':
$this->write("Please enter the Cron-ID: ");
$cronId = $this->readInput();
try {
$this->runCron($cronId);
} catch (QUI\Exception $Exception) {
$this->writeLn($Exception->getMessage(), 'red');
$this->resetColor();
$this->writeLn('');
}
$this->commandRead();
break;
default: default:
$this->writeLn('Command not found, please type another command', $this->writeLn(
'red'); 'Command not found, please type another command',
'red'
);
$this->commandRead(); $this->commandRead();
} }
} }
...@@ -122,7 +145,7 @@ class Console extends \QUI\System\Console\Tool ...@@ -122,7 +145,7 @@ class Console extends \QUI\System\Console\Tool
public function listCrons() public function listCrons()
{ {
$Manager = new Manager(); $Manager = new Manager();
$list = $Manager->getList(); $list = $Manager->getList();
$this->writeLn('Cron list:'); $this->writeLn('Cron list:');
$this->writeLn('======================================================='); $this->writeLn('=======================================================');
...@@ -133,12 +156,15 @@ class Console extends \QUI\System\Console\Tool ...@@ -133,12 +156,15 @@ class Console extends \QUI\System\Console\Tool
continue; continue;
} }
$time = $entry['min'].' '.$entry['hour'].' '.$entry['day'].' ' $time = $entry['min']
.$entry['month']; . ' ' . $entry['hour']
. ' ' . $entry['day']
. ' ' . $entry['month'];
$exec = $entry['exec']; $exec = $entry['exec'];
$this->writeLn('ID: '.$entry['id']); $this->writeLn('ID: ' . $entry['id']);
$this->writeLn($time."\t".$exec, 'green'); $this->writeLn($time . "\t" . $exec, 'green');
$this->resetColor(); $this->resetColor();
$this->writeLn(''); $this->writeLn('');
...@@ -154,19 +180,22 @@ class Console extends \QUI\System\Console\Tool ...@@ -154,19 +180,22 @@ class Console extends \QUI\System\Console\Tool
public function listAllCrons() public function listAllCrons()
{ {
$Manager = new Manager(); $Manager = new Manager();
$list = $Manager->getList(); $list = $Manager->getList();
$this->writeLn('Cron list:'); $this->writeLn('Cron list:');
$this->writeLn('======================================================='); $this->writeLn('=======================================================');
$this->writeLn(''); $this->writeLn('');
foreach ($list as $entry) { foreach ($list as $entry) {
$time = $entry['min'].' '.$entry['hour'].' '.$entry['day'].' ' $time = $entry['min']
.$entry['month']; . ' ' . $entry['hour']
. ' ' . $entry['day']
. ' ' . $entry['month'];
$exec = $entry['exec']; $exec = $entry['exec'];
$this->writeLn('ID: '.$entry['id']); $this->writeLn('ID: ' . $entry['id']);
$this->writeLn($time."\t".$exec, 'green'); $this->writeLn($time . "\t" . $exec, 'green');
$this->resetColor(); $this->resetColor();
$this->writeLn(''); $this->writeLn('');
...@@ -175,4 +204,26 @@ class Console extends \QUI\System\Console\Tool ...@@ -175,4 +204,26 @@ class Console extends \QUI\System\Console\Tool
$this->writeLn('======================================================='); $this->writeLn('=======================================================');
$this->writeLn(''); $this->writeLn('');
} }
/**
* Run a specific cron
*
* @param Boolean|Integer $cronId - ID of the cron
* @throws QUI\Exception
*/
public function runCron($cronId = false)
{
$Manager = new Manager();
$cron = $Manager->getCronById($cronId);
if (!$cron) {
throw new QUI\Exception('Cron not found');
}
$this->writeLn('Execute Cron: ' . $cronId. ' '. $cron['title']);
$Manager->executeCron($cronId);
$this->writeLn('=======================================================');
$this->writeLn('');
}
} }
0% oder .
You are about to add 0 people to the discussion. Proceed with caution.
Bearbeitung dieser Nachricht zuerst beenden!
Bitte registrieren oder zum Kommentieren