@@ -1,19 +1,12 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace Alpixel\Bundle\CronBundle\Command; |
| 3 | 3 | use Doctrine\ORM\EntityManager; |
| 4 | - |
|
| 5 | 4 | use Symfony\Component\Console\Input\ArgvInput; |
| 6 | - |
|
| 7 | 5 | use Alpixel\Bundle\CronBundle\Entity\CronJobResult; |
| 8 | - |
|
| 9 | 6 | use Alpixel\Bundle\CronBundle\Entity\CronJob; |
| 10 | - |
|
| 11 | 7 | use Symfony\Component\Console\Output\OutputInterface; |
| 12 | - |
|
| 13 | 8 | use Symfony\Component\Console\Input\InputInterface; |
| 14 | - |
|
| 15 | 9 | use Symfony\Component\Console\Input\InputArgument; |
| 16 | - |
|
| 17 | 10 | use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
| 18 | 11 | |
| 19 | 12 | class CronRunCommand extends ContainerAwareCommand |
@@ -32,17 +32,17 @@ discard block |
||
| 32 | 32 | $jobRepo = $em->getRepository('CronBundle:CronJob'); |
| 33 | 33 | |
| 34 | 34 | $jobsToRun = array(); |
| 35 | - if($jobName = $input->getArgument('job')) |
|
| 35 | + if ($jobName = $input->getArgument('job')) |
|
| 36 | 36 | { |
| 37 | 37 | try |
| 38 | 38 | { |
| 39 | 39 | $jobObj = $jobRepo->findOneByCommand($jobName); |
| 40 | - if($jobObj->getEnabled()) |
|
| 40 | + if ($jobObj->getEnabled()) |
|
| 41 | 41 | { |
| 42 | 42 | $jobsToRun = array($jobObj); |
| 43 | 43 | } |
| 44 | 44 | } |
| 45 | - catch(\Exception $e) |
|
| 45 | + catch (\Exception $e) |
|
| 46 | 46 | { |
| 47 | 47 | $output->writeln("Couldn't find a job by the name of $jobName"); |
| 48 | 48 | return CronJobResult::FAILED; |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | $jobCount = count($jobsToRun); |
| 57 | 57 | $output->writeln("Running $jobCount jobs:"); |
| 58 | 58 | |
| 59 | - foreach($jobsToRun as $job) |
|
| 59 | + foreach ($jobsToRun as $job) |
|
| 60 | 60 | { |
| 61 | 61 | $this->runJob($job, $output, $em); |
| 62 | 62 | } |
@@ -71,13 +71,13 @@ discard block |
||
| 71 | 71 | |
| 72 | 72 | protected function runJob(CronJob $job, OutputInterface $output, EntityManager $em) |
| 73 | 73 | { |
| 74 | - $output->write("Running " . $job->getCommand() . ": "); |
|
| 74 | + $output->write("Running ".$job->getCommand().": "); |
|
| 75 | 75 | |
| 76 | 76 | try |
| 77 | 77 | { |
| 78 | 78 | $commandToRun = $this->getApplication()->get($job->getCommand()); |
| 79 | 79 | } |
| 80 | - catch(InvalidArgumentException $ex) |
|
| 80 | + catch (InvalidArgumentException $ex) |
|
| 81 | 81 | { |
| 82 | 82 | $output->writeln(" skipped (command no longer exists)"); |
| 83 | 83 | $this->recordJobResult($em, $job, 0, "Command no longer exists", CronJobResult::SKIPPED); |
@@ -94,32 +94,32 @@ discard block |
||
| 94 | 94 | { |
| 95 | 95 | $returnCode = $commandToRun->execute($emptyInput, $jobOutput); |
| 96 | 96 | } |
| 97 | - catch(\Exception $ex) |
|
| 97 | + catch (\Exception $ex) |
|
| 98 | 98 | { |
| 99 | 99 | $returnCode = CronJobResult::FAILED; |
| 100 | 100 | $jobOutput->writeln(""); |
| 101 | - $jobOutput->writeln("Job execution failed with exception " . get_class($ex) . ":"); |
|
| 101 | + $jobOutput->writeln("Job execution failed with exception ".get_class($ex).":"); |
|
| 102 | 102 | $jobOutput->writeln($ex->__toString()); |
| 103 | 103 | } |
| 104 | 104 | $jobEnd = microtime(true); |
| 105 | 105 | |
| 106 | 106 | // Clamp the result to accepted values |
| 107 | - if($returnCode < CronJobResult::RESULT_MIN || $returnCode > CronJobResult::RESULT_MAX) |
|
| 107 | + if ($returnCode < CronJobResult::RESULT_MIN || $returnCode > CronJobResult::RESULT_MAX) |
|
| 108 | 108 | { |
| 109 | 109 | $returnCode = CronJobResult::FAILED; |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | // Output the result |
| 113 | 113 | $statusStr = "unknown"; |
| 114 | - if($returnCode == CronJobResult::SKIPPED) |
|
| 114 | + if ($returnCode == CronJobResult::SKIPPED) |
|
| 115 | 115 | { |
| 116 | 116 | $statusStr = "skipped"; |
| 117 | 117 | } |
| 118 | - elseif($returnCode == CronJobResult::SUCCEEDED) |
|
| 118 | + elseif ($returnCode == CronJobResult::SUCCEEDED) |
|
| 119 | 119 | { |
| 120 | 120 | $statusStr = "succeeded"; |
| 121 | 121 | } |
| 122 | - elseif($returnCode == CronJobResult::FAILED) |
|
| 122 | + elseif ($returnCode == CronJobResult::FAILED) |
|
| 123 | 123 | { |
| 124 | 124 | $statusStr = "failed"; |
| 125 | 125 | } |
@@ -1,21 +1,12 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace Alpixel\Bundle\CronBundle\Command; |
| 3 | 3 | use Alpixel\Bundle\CronBundle\Entity\CronJob; |
| 4 | - |
|
| 5 | 4 | use Doctrine\ORM\EntityManager; |
| 6 | - |
|
| 7 | 5 | use Symfony\Component\Console\Command\Command; |
| 8 | - |
|
| 9 | 6 | use Alpixel\Bundle\CronBundle\Annotation\CronJob as CronJobAnno; |
| 10 | - |
|
| 11 | -use Symfony\Bundle\DoctrineBundle\Registry; |
|
| 12 | - |
|
| 13 | 7 | use Symfony\Component\Console\Output\OutputInterface; |
| 14 | - |
|
| 15 | 8 | use Symfony\Component\Console\Input\InputInterface; |
| 16 | - |
|
| 17 | 9 | use Symfony\Component\Console\Input\InputOption; |
| 18 | - |
|
| 19 | 10 | use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
| 20 | 11 | |
| 21 | 12 | class CronScanCommand extends ContainerAwareCommand |
@@ -42,16 +42,16 @@ discard block |
||
| 42 | 42 | // Enumerate all the jobs currently loaded |
| 43 | 43 | $reader = $this->getContainer()->get("annotation_reader"); |
| 44 | 44 | |
| 45 | - foreach($this->getApplication()->all() as $command) |
|
| 45 | + foreach ($this->getApplication()->all() as $command) |
|
| 46 | 46 | { |
| 47 | 47 | // Check for an @CronJob annotation |
| 48 | 48 | $reflClass = new \ReflectionClass($command); |
| 49 | - foreach($reader->getClassAnnotations($reflClass) as $anno) |
|
| 49 | + foreach ($reader->getClassAnnotations($reflClass) as $anno) |
|
| 50 | 50 | { |
| 51 | - if($anno instanceof CronJobAnno) |
|
| 51 | + if ($anno instanceof CronJobAnno) |
|
| 52 | 52 | { |
| 53 | 53 | $job = $command->getName(); |
| 54 | - if(array_key_exists($job, $knownJobs)) |
|
| 54 | + if (array_key_exists($job, $knownJobs)) |
|
| 55 | 55 | { |
| 56 | 56 | // Clear it from the known jobs so that we don't try to delete it |
| 57 | 57 | unset($knownJobs[$job]); |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | // Update the job if necessary |
| 60 | 60 | $currentJob = $jobRepo->findOneByCommand($job); |
| 61 | 61 | $currentJob->setDescription($command->getDescription()); |
| 62 | - if($currentJob->getInterval() != $anno->value) |
|
| 62 | + if ($currentJob->getInterval() != $anno->value) |
|
| 63 | 63 | { |
| 64 | 64 | $newTime = new \DateTime(); |
| 65 | 65 | $newTime = $newTime->add(new \DateInterval($anno->value)); |
@@ -78,9 +78,9 @@ discard block |
||
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | // Clear any jobs that weren't found |
| 81 | - if(!$keepDeleted) |
|
| 81 | + if (!$keepDeleted) |
|
| 82 | 82 | { |
| 83 | - foreach(array_keys($knownJobs) as $deletedJob) |
|
| 83 | + foreach (array_keys($knownJobs) as $deletedJob) |
|
| 84 | 84 | { |
| 85 | 85 | $output->writeln("Deleting job: $deletedJob"); |
| 86 | 86 | $jobToDelete = $jobRepo->findOneByCommand($deletedJob); |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | $newJob->setNextRun(new \DateTime()); |
| 102 | 102 | $newJob->setEnabled(!$defaultDisabled); |
| 103 | 103 | |
| 104 | - $output->writeln("Added the job " . $newJob->getCommand() . " with interval " . $newJob->getInterval()); |
|
| 104 | + $output->writeln("Added the job ".$newJob->getCommand()." with interval ".$newJob->getInterval()); |
|
| 105 | 105 | $em->persist($newJob); |
| 106 | 106 | } |
| 107 | 107 | } |
@@ -1,15 +1,10 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace Alpixel\Bundle\CronBundle\Command; |
| 3 | 3 | use Alpixel\Bundle\CronBundle\Entity\CronJobResult; |
| 4 | - |
|
| 5 | 4 | use Alpixel\Bundle\CronBundle\Entity\CronJob; |
| 6 | - |
|
| 7 | 5 | use Symfony\Component\Console\Output\OutputInterface; |
| 8 | - |
|
| 9 | 6 | use Symfony\Component\Console\Input\InputInterface; |
| 10 | - |
|
| 11 | 7 | use Symfony\Component\Console\Input\InputArgument; |
| 12 | - |
|
| 13 | 8 | use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
| 14 | 9 | |
| 15 | 10 | class CronStatusCommand extends ContainerAwareCommand |
@@ -27,13 +27,13 @@ discard block |
||
| 27 | 27 | $output->writeln("Cron job statuses:"); |
| 28 | 28 | |
| 29 | 29 | $cronJobs = array(); |
| 30 | - if($jobName = $input->getArgument('job')) |
|
| 30 | + if ($jobName = $input->getArgument('job')) |
|
| 31 | 31 | { |
| 32 | 32 | try |
| 33 | 33 | { |
| 34 | 34 | $cronJobs = array($jobRepo->findOneByCommand($jobName)); |
| 35 | 35 | } |
| 36 | - catch(\Exception $e) |
|
| 36 | + catch (\Exception $e) |
|
| 37 | 37 | { |
| 38 | 38 | $output->writeln("Couldn't find a job by the name of $jobName"); |
| 39 | 39 | return CronJobResult::FAILED; |
@@ -44,16 +44,16 @@ discard block |
||
| 44 | 44 | $cronJobs = $em->getRepository('CronBundle:CronJob')->findAll(); |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | - foreach($cronJobs as $cronJob) |
|
| 47 | + foreach ($cronJobs as $cronJob) |
|
| 48 | 48 | { |
| 49 | - $output->write(" - " . $cronJob->getCommand()); |
|
| 50 | - if(!$cronJob->getEnabled()) |
|
| 49 | + $output->write(" - ".$cronJob->getCommand()); |
|
| 50 | + if (!$cronJob->getEnabled()) |
|
| 51 | 51 | { |
| 52 | 52 | $output->write(" (disabled)"); |
| 53 | 53 | } |
| 54 | 54 | $output->writeln(""); |
| 55 | - $output->writeln(" Description: " . $cronJob->getDescription()); |
|
| 56 | - if(!$cronJob->getEnabled()) |
|
| 55 | + $output->writeln(" Description: ".$cronJob->getDescription()); |
|
| 56 | + if (!$cronJob->getEnabled()) |
|
| 57 | 57 | { |
| 58 | 58 | $output->writeln(" Not scheduled"); |
| 59 | 59 | } |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | { |
| 62 | 62 | $output->write(" Scheduled for: "); |
| 63 | 63 | $now = new \DateTime(); |
| 64 | - if($cronJob->getNextRun() <= $now) |
|
| 64 | + if ($cronJob->getNextRun() <= $now) |
|
| 65 | 65 | { |
| 66 | 66 | $output->writeln("Next run"); |
| 67 | 67 | } |
@@ -70,10 +70,10 @@ discard block |
||
| 70 | 70 | $output->writeln(strftime("%c", $cronJob->getNextRun()->getTimestamp())); |
| 71 | 71 | } |
| 72 | 72 | } |
| 73 | - if($cronJob->getMostRecentRun()) |
|
| 73 | + if ($cronJob->getMostRecentRun()) |
|
| 74 | 74 | { |
| 75 | 75 | $status = "Unknown"; |
| 76 | - switch($cronJob->getMostRecentRun()->getResult()) |
|
| 76 | + switch ($cronJob->getMostRecentRun()->getResult()) |
|
| 77 | 77 | { |
| 78 | 78 | case CronJobResult::SUCCEEDED: |
| 79 | 79 | $status = "Successful"; |
@@ -24,15 +24,15 @@ |
||
| 24 | 24 | $jobRepo = $em->getRepository('CronBundle:CronJob'); |
| 25 | 25 | |
| 26 | 26 | $job = $jobRepo->findOneByCommand($jobName); |
| 27 | - if(!$job) |
|
| 27 | + if (!$job) |
|
| 28 | 28 | { |
| 29 | - $output->writeln("Couldn't find a job by the name of " . $jobName); |
|
| 29 | + $output->writeln("Couldn't find a job by the name of ".$jobName); |
|
| 30 | 30 | return CronJobResult::FAILED; |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | $job->setEnabled(true); |
| 34 | 34 | $em->flush(); |
| 35 | 35 | |
| 36 | - $output->writeln("Enabled cron job by the name of " . $jobName); |
|
| 36 | + $output->writeln("Enabled cron job by the name of ".$jobName); |
|
| 37 | 37 | } |
| 38 | 38 | } |
@@ -15,7 +15,7 @@ |
||
| 15 | 15 | |
| 16 | 16 | public function doWrite($message, $newline) { |
| 17 | 17 | $this->backingStore .= $message; |
| 18 | - if($newline) { |
|
| 18 | + if ($newline) { |
|
| 19 | 19 | $this->backingStore .= "\n"; |
| 20 | 20 | } |
| 21 | 21 | } |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | $em = $this->getContainer()->get("doctrine.orm.entity_manager"); |
| 26 | 26 | $job = $input->getArgument('job'); |
| 27 | 27 | |
| 28 | - if($job) |
|
| 28 | + if ($job) |
|
| 29 | 29 | { |
| 30 | 30 | $output->writeln("Pruning logs for cron job $job"); |
| 31 | 31 | } |
@@ -34,12 +34,12 @@ discard block |
||
| 34 | 34 | $output->writeln("Pruning logs for all cron jobs"); |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | - if($job) |
|
| 37 | + if ($job) |
|
| 38 | 38 | { |
| 39 | 39 | $jobObj = $em->getRepository('CronBundle:CronJob')->findOneByCommand($job); |
| 40 | - if(!$jobObj) |
|
| 40 | + if (!$jobObj) |
|
| 41 | 41 | { |
| 42 | - $output->writeln("Couldn't find a job by the name of " . $job); |
|
| 42 | + $output->writeln("Couldn't find a job by the name of ".$job); |
|
| 43 | 43 | return CronJobResult::FAILED; |
| 44 | 44 | } |
| 45 | 45 | |
@@ -26,15 +26,15 @@ |
||
| 26 | 26 | $jobRepo = $em->getRepository('CronBundle:CronJob'); |
| 27 | 27 | |
| 28 | 28 | $job = $jobRepo->findOneByCommand($jobName); |
| 29 | - if(!$job) |
|
| 29 | + if (!$job) |
|
| 30 | 30 | { |
| 31 | - $output->writeln("Couldn't find a job by the name of " . $jobName); |
|
| 31 | + $output->writeln("Couldn't find a job by the name of ".$jobName); |
|
| 32 | 32 | return CronJobResult::FAILED; |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | $job->setEnabled(false); |
| 36 | 36 | $em->flush(); |
| 37 | 37 | |
| 38 | - $output->writeln("Disabled cron job by the name of " . $jobName); |
|
| 38 | + $output->writeln("Disabled cron job by the name of ".$jobName); |
|
| 39 | 39 | } |
| 40 | 40 | } |
@@ -10,7 +10,7 @@ |
||
| 10 | 10 | ->createQuery("SELECT job.command FROM CronBundle:CronJob job") |
| 11 | 11 | ->getScalarResult(); |
| 12 | 12 | $toRet = array(); |
| 13 | - foreach($data as $datum) |
|
| 13 | + foreach ($data as $datum) |
|
| 14 | 14 | { |
| 15 | 15 | $toRet[] = $datum['command']; |
| 16 | 16 | } |