@@ -653,175 +653,175 @@ |
||
653 | 653 | |
654 | 654 | private function cycle() { |
655 | 655 | |
656 | - // fire extender ready event |
|
656 | + // fire extender ready event |
|
657 | 657 | |
658 | - $this->events->fire("extender", "VOID", $this); |
|
658 | + $this->events->fire("extender", "VOID", $this); |
|
659 | 659 | |
660 | - // dispatch signals (if multithread active) |
|
660 | + // dispatch signals (if multithread active) |
|
661 | 661 | |
662 | - if ( $this->getMultithreadMode() ) pcntl_signal_dispatch(); |
|
662 | + if ( $this->getMultithreadMode() ) pcntl_signal_dispatch(); |
|
663 | 663 | |
664 | - // if extender is paused (SIGINT), skip to extend |
|
664 | + // if extender is paused (SIGINT), skip to extend |
|
665 | 665 | |
666 | - if ( $this->paused ) return; |
|
666 | + if ( $this->paused ) return; |
|
667 | 667 | |
668 | - // fix relative timestamp |
|
668 | + // fix relative timestamp |
|
669 | 669 | |
670 | - $this->timestamp = microtime(true); |
|
670 | + $this->timestamp = microtime(true); |
|
671 | 671 | |
672 | - // fire tasktable event |
|
672 | + // fire tasktable event |
|
673 | 673 | |
674 | - $this->tasks = $this->events->fire("extender.tasks", "TASKSTABLE", $this->tasks); |
|
674 | + $this->tasks = $this->events->fire("extender.tasks", "TASKSTABLE", $this->tasks); |
|
675 | 675 | |
676 | - // get the next planned activity interval |
|
676 | + // get the next planned activity interval |
|
677 | 677 | |
678 | - $plans = Planner::get(); |
|
678 | + $plans = Planner::get(); |
|
679 | 679 | |
680 | - if ( !is_null($plans) AND $this->timestamp < $plans ) { |
|
680 | + if ( !is_null($plans) AND $this->timestamp < $plans ) { |
|
681 | 681 | |
682 | - // nothing to do right now, still waiting if in daemon mode |
|
682 | + // nothing to do right now, still waiting if in daemon mode |
|
683 | 683 | |
684 | - $this->logger->info("Next planned job: ".date('c', $plans)); |
|
684 | + $this->logger->info("Next planned job: ".date('c', $plans)); |
|
685 | 685 | |
686 | - $this->logger->notice("Extender completed\n"); |
|
686 | + $this->logger->notice("Extender completed\n"); |
|
687 | 687 | |
688 | - if ( $this->getDaemonMode() === false ) { |
|
688 | + if ( $this->getDaemonMode() === false ) { |
|
689 | 689 | |
690 | - $this->shutdown(true); |
|
690 | + $this->shutdown(true); |
|
691 | 691 | |
692 | - self::end(0); |
|
692 | + self::end(0); |
|
693 | 693 | |
694 | - } |
|
694 | + } |
|
695 | 695 | |
696 | - return; |
|
696 | + return; |
|
697 | 697 | |
698 | - } |
|
698 | + } |
|
699 | 699 | |
700 | - // if no plan is retrieved, try to retrieve it from scheduler |
|
700 | + // if no plan is retrieved, try to retrieve it from scheduler |
|
701 | 701 | |
702 | - try { |
|
702 | + try { |
|
703 | 703 | |
704 | - // get schedules and dispatch schedule event |
|
704 | + // get schedules and dispatch schedule event |
|
705 | 705 | |
706 | - list($schedules, $planned) = Scheduler::getSchedules($this->logger, $this->timestamp); |
|
706 | + list($schedules, $planned) = Scheduler::getSchedules($this->logger, $this->timestamp); |
|
707 | 707 | |
708 | - // write next planned activity interval |
|
708 | + // write next planned activity interval |
|
709 | 709 | |
710 | - if ( !is_null($planned) AND $planned != 0 ) Planner::set($planned); |
|
710 | + if ( !is_null($planned) AND $planned != 0 ) Planner::set($planned); |
|
711 | 711 | |
712 | - $scheduled = new Schedule(); |
|
712 | + $scheduled = new Schedule(); |
|
713 | 713 | |
714 | - $scheduled->setSchedules($schedules); |
|
714 | + $scheduled->setSchedules($schedules); |
|
715 | 715 | |
716 | - // expose the current shcedule via events |
|
716 | + // expose the current shcedule via events |
|
717 | 717 | |
718 | - $scheduled = $this->events->fire("extender.schedule", "SCHEDULE", $scheduled); |
|
718 | + $scheduled = $this->events->fire("extender.schedule", "SCHEDULE", $scheduled); |
|
719 | 719 | |
720 | - // if no jobs in queue, exit gracefully |
|
720 | + // if no jobs in queue, exit gracefully |
|
721 | 721 | |
722 | - if ( $scheduled->howMany() == 0 ) { |
|
722 | + if ( $scheduled->howMany() == 0 ) { |
|
723 | 723 | |
724 | - $this->logger->info("No jobs to process right now, exiting"); |
|
724 | + $this->logger->info("No jobs to process right now, exiting"); |
|
725 | 725 | |
726 | - $this->logger->notice("Extender completed\n"); |
|
726 | + $this->logger->notice("Extender completed\n"); |
|
727 | 727 | |
728 | - if ( $this->getDaemonMode() === false ) { |
|
728 | + if ( $this->getDaemonMode() === false ) { |
|
729 | 729 | |
730 | - $this->shutdown(true); |
|
730 | + $this->shutdown(true); |
|
731 | 731 | |
732 | - self::end(0); |
|
732 | + self::end(0); |
|
733 | 733 | |
734 | - } |
|
734 | + } |
|
735 | 735 | |
736 | - return; |
|
736 | + return; |
|
737 | 737 | |
738 | - } |
|
738 | + } |
|
739 | 739 | |
740 | - // compose jobs |
|
740 | + // compose jobs |
|
741 | 741 | |
742 | - foreach ( $scheduled->getSchedules() as $schedule ) { |
|
742 | + foreach ( $scheduled->getSchedules() as $schedule ) { |
|
743 | 743 | |
744 | - if ( $this->tasks->isRegistered($schedule['task']) ) { |
|
744 | + if ( $this->tasks->isRegistered($schedule['task']) ) { |
|
745 | 745 | |
746 | - $job = new Job(); |
|
746 | + $job = new Job(); |
|
747 | 747 | |
748 | - $job->setName($schedule['name']) |
|
749 | - ->setId($schedule['id']) |
|
750 | - ->setParameters(unserialize($schedule['params'])) |
|
751 | - ->setTask($schedule['task']) |
|
752 | - ->setClass($this->tasks->getClass($schedule['task'])); |
|
748 | + $job->setName($schedule['name']) |
|
749 | + ->setId($schedule['id']) |
|
750 | + ->setParameters(unserialize($schedule['params'])) |
|
751 | + ->setTask($schedule['task']) |
|
752 | + ->setClass($this->tasks->getClass($schedule['task'])); |
|
753 | 753 | |
754 | - $this->runner->addJob($job); |
|
754 | + $this->runner->addJob($job); |
|
755 | 755 | |
756 | - } else { |
|
756 | + } else { |
|
757 | 757 | |
758 | - $this->logger->warning("Skipping job due to unknown task", array( |
|
759 | - "ID" => $schedule['id'], |
|
760 | - "NAME" => $schedule['name'], |
|
761 | - "TASK" => $schedule['task'] |
|
762 | - )); |
|
758 | + $this->logger->warning("Skipping job due to unknown task", array( |
|
759 | + "ID" => $schedule['id'], |
|
760 | + "NAME" => $schedule['name'], |
|
761 | + "TASK" => $schedule['task'] |
|
762 | + )); |
|
763 | 763 | |
764 | - } |
|
764 | + } |
|
765 | 765 | |
766 | - } |
|
766 | + } |
|
767 | 767 | |
768 | - // lauch runner |
|
768 | + // lauch runner |
|
769 | 769 | |
770 | - $result = $this->runner->run(); |
|
770 | + $result = $this->runner->run(); |
|
771 | 771 | |
772 | - // free runner for next cycle |
|
772 | + // free runner for next cycle |
|
773 | 773 | |
774 | - $this->runner->free(); |
|
774 | + $this->runner->free(); |
|
775 | 775 | |
776 | - // compose results |
|
776 | + // compose results |
|
777 | 777 | |
778 | - $results = new JobsResult($result); |
|
778 | + $results = new JobsResult($result); |
|
779 | 779 | |
780 | - // update schedules |
|
780 | + // update schedules |
|
781 | 781 | |
782 | - Scheduler::updateSchedules($this->logger, $result); |
|
782 | + Scheduler::updateSchedules($this->logger, $result); |
|
783 | 783 | |
784 | - // increment counters |
|
784 | + // increment counters |
|
785 | 785 | |
786 | - foreach ( $result as $r ) { |
|
786 | + foreach ( $result as $r ) { |
|
787 | 787 | |
788 | - if ( $r[2] ) $this->completed_processes++; |
|
788 | + if ( $r[2] ) $this->completed_processes++; |
|
789 | 789 | |
790 | - else $this->failed_processes++; |
|
790 | + else $this->failed_processes++; |
|
791 | 791 | |
792 | - } |
|
792 | + } |
|
793 | 793 | |
794 | - } catch (Exception $e) { |
|
794 | + } catch (Exception $e) { |
|
795 | 795 | |
796 | - $this->logger->error($e->getMessage()); |
|
796 | + $this->logger->error($e->getMessage()); |
|
797 | 797 | |
798 | - if ( $this->getDaemonMode() === false ) { |
|
798 | + if ( $this->getDaemonMode() === false ) { |
|
799 | 799 | |
800 | - self::end(1); |
|
800 | + self::end(1); |
|
801 | 801 | |
802 | - } |
|
802 | + } |
|
803 | 803 | |
804 | - } |
|
804 | + } |
|
805 | 805 | |
806 | - // fire result event |
|
806 | + // fire result event |
|
807 | 807 | |
808 | - $this->events->fire("extender.result", "VOID", $results); |
|
808 | + $this->events->fire("extender.result", "VOID", $results); |
|
809 | 809 | |
810 | - $this->logger->notice("Extender completed\n"); |
|
810 | + $this->logger->notice("Extender completed\n"); |
|
811 | 811 | |
812 | - // show summary (if -s) |
|
812 | + // show summary (if -s) |
|
813 | 813 | |
814 | - if ( $this->summary_mode ) self::showSummary($this->timestamp, $result, $this->color); |
|
814 | + if ( $this->summary_mode ) self::showSummary($this->timestamp, $result, $this->color); |
|
815 | 815 | |
816 | - Status::dump($this->timestamp_absolute, $this->parent_pid, $this->completed_processes, $this->failed_processes, $this->paused); |
|
816 | + Status::dump($this->timestamp_absolute, $this->parent_pid, $this->completed_processes, $this->failed_processes, $this->paused); |
|
817 | 817 | |
818 | - if ( $this->getDaemonMode() === false ) { |
|
818 | + if ( $this->getDaemonMode() === false ) { |
|
819 | 819 | |
820 | - $this->shutdown(true); |
|
820 | + $this->shutdown(true); |
|
821 | 821 | |
822 | - self::end(0); |
|
822 | + self::end(0); |
|
823 | 823 | |
824 | - } |
|
824 | + } |
|
825 | 825 | |
826 | 826 | } |
827 | 827 |
@@ -482,7 +482,7 @@ |
||
482 | 482 | ) |
483 | 483 | )) : 1; |
484 | 484 | |
485 | - while (true) { |
|
485 | + while ( true ) { |
|
486 | 486 | |
487 | 487 | $this->cycle(); |
488 | 488 |
@@ -340,8 +340,7 @@ discard block |
||
340 | 340 | |
341 | 341 | $db->tablePrefix(EXTENDER_DATABASE_PREFIX)->table(EXTENDER_DATABASE_TABLE_JOBS)->keys("lastrun")->values($lastrun)->where('name', '=', $name)->update(); |
342 | 342 | |
343 | - } |
|
344 | - catch (DatabaseException $de) { |
|
343 | + } catch (DatabaseException $de) { |
|
345 | 344 | |
346 | 345 | unset($db); |
347 | 346 | |
@@ -474,8 +473,7 @@ discard block |
||
474 | 473 | |
475 | 474 | if ( $e_count == 5 ) $e_array[] = "*"; |
476 | 475 | |
477 | - } |
|
478 | - catch (Exception $e) { |
|
476 | + } catch (Exception $e) { |
|
479 | 477 | |
480 | 478 | throw $e; |
481 | 479 | |
@@ -516,8 +514,7 @@ discard block |
||
516 | 514 | ->where("enabled", "=", true) |
517 | 515 | ->get(); |
518 | 516 | |
519 | - } |
|
520 | - catch (DatabaseException $de) { |
|
517 | + } catch (DatabaseException $de) { |
|
521 | 518 | |
522 | 519 | unset($db); |
523 | 520 | |
@@ -565,8 +562,7 @@ discard block |
||
565 | 562 | |
566 | 563 | $next_calculated_run = $cron->getNextRunDate($last_date)->format('U'); |
567 | 564 | |
568 | - } |
|
569 | - catch (Exception $e) { |
|
565 | + } catch (Exception $e) { |
|
570 | 566 | |
571 | 567 | $logger->error("Job ".$job['name']." cannot be executed due to cron parsing error", array( |
572 | 568 | "ERROR" => $e->getMessage(), |
@@ -619,8 +615,7 @@ discard block |
||
619 | 615 | |
620 | 616 | $next_calculated_run = $cron->getNextRunDate($last_date)->format('U'); |
621 | 617 | |
622 | - } |
|
623 | - catch (Exception $e) { |
|
618 | + } catch (Exception $e) { |
|
624 | 619 | |
625 | 620 | return false; |
626 | 621 |
@@ -200,7 +200,7 @@ |
||
200 | 200 | |
201 | 201 | $commands = Spyc::YAMLLoad(EXTENDER_COMMANDS_CONFIG); |
202 | 202 | |
203 | - foreach ($commands as $command => $parameters) { |
|
203 | + foreach ( $commands as $command => $parameters ) { |
|
204 | 204 | |
205 | 205 | $controller->add($command, $parameters["data"]); |
206 | 206 |
@@ -74,8 +74,6 @@ discard block |
||
74 | 74 | /** |
75 | 75 | * Class constructor |
76 | 76 | * |
77 | - * @param \Console_CommandLine $parser |
|
78 | - * @param \Monolog\logger $logger |
|
79 | 77 | */ |
80 | 78 | public function add($command, $parameters) { |
81 | 79 | |
@@ -140,7 +138,7 @@ discard block |
||
140 | 138 | /** |
141 | 139 | * Execute command |
142 | 140 | * |
143 | - * @param string $command Command to execute |
|
141 | + * @param string $command_name Command to execute |
|
144 | 142 | * @param array $options Options provided |
145 | 143 | * @param array $args Arguments provided |
146 | 144 | * @param Console_Color2 $color Injected Console_Color2 instance |
@@ -185,6 +185,9 @@ |
||
185 | 185 | |
186 | 186 | } |
187 | 187 | |
188 | + /** |
|
189 | + * @param integer $looptime |
|
190 | + */ |
|
188 | 191 | public static function getLoopTime($looptime) { |
189 | 192 | |
190 | 193 | return filter_var($looptime, FILTER_VALIDATE_INT, array( |
@@ -109,29 +109,29 @@ discard block |
||
109 | 109 | |
110 | 110 | $this->logger->notice("Starting daemon (looping each ".$this->looptime." secs, pid: ".$this->pid.")"); |
111 | 111 | |
112 | - $this->events->emit( new DaemonEvent('start', $this) ); |
|
112 | + $this->events->emit(new DaemonEvent('start', $this)); |
|
113 | 113 | |
114 | - while ($this->loopactive) { |
|
114 | + while ( $this->loopactive ) { |
|
115 | 115 | |
116 | 116 | $start = microtime(true); |
117 | 117 | |
118 | 118 | pcntl_signal_dispatch(); |
119 | 119 | |
120 | - $this->events->emit( new DaemonEvent('preloop', $this) ); |
|
120 | + $this->events->emit(new DaemonEvent('preloop', $this)); |
|
121 | 121 | |
122 | - if ( $this->runlock->check() && $this->loopactive) { |
|
122 | + if ( $this->runlock->check() && $this->loopactive ) { |
|
123 | 123 | |
124 | - $this->events->emit( new DaemonEvent('loopstart', $this) ); |
|
124 | + $this->events->emit(new DaemonEvent('loopstart', $this)); |
|
125 | 125 | |
126 | 126 | $this->loop(); |
127 | 127 | |
128 | - $this->events->emit( new DaemonEvent('loopstop', $this) ); |
|
128 | + $this->events->emit(new DaemonEvent('loopstop', $this)); |
|
129 | 129 | |
130 | 130 | $this->loopcount++; |
131 | 131 | |
132 | 132 | } |
133 | 133 | |
134 | - $this->events->emit( new DaemonEvent('postloop', $this) ); |
|
134 | + $this->events->emit(new DaemonEvent('postloop', $this)); |
|
135 | 135 | |
136 | 136 | $this->loopelapsed = (microtime(true) - $start); |
137 | 137 | |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | |
144 | 144 | $this->logger->notice("Stopping daemon (pid: ".$this->pid.")"); |
145 | 145 | |
146 | - $this->events->emit( new DaemonEvent('stop', $this) ); |
|
146 | + $this->events->emit(new DaemonEvent('stop', $this)); |
|
147 | 147 | |
148 | 148 | $this->end(0); |
149 | 149 |
@@ -45,8 +45,7 @@ |
||
45 | 45 | LoggerInterface $logger, |
46 | 46 | Emitter $events, |
47 | 47 | $looptime = 1, |
48 | - $niceness = null) |
|
49 | - { |
|
48 | + $niceness = null) { |
|
50 | 49 | |
51 | 50 | parent::__construct($configuration, $logger, $events, $niceness); |
52 | 51 |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | /** |
123 | 123 | * Runner constructor |
124 | 124 | * |
125 | - * @param \Comodojo\Extender\Debug $logger Logger instance |
|
125 | + * @param Logger $logger Logger instance |
|
126 | 126 | * @param bool $multithread Enable/disable multithread mode |
127 | 127 | * @param int $max_result_bytes_in_multithread Max result bytes |
128 | 128 | * @param int $max_childs_runtime Max child runtime |
@@ -676,6 +676,8 @@ discard block |
||
676 | 676 | /** |
677 | 677 | * Change child process priority according to EXTENDER_NICENESS |
678 | 678 | * |
679 | + * @param integer $pid |
|
680 | + * @param Logger $logger |
|
679 | 681 | */ |
680 | 682 | private static function adjustNiceness($pid, $logger) { |
681 | 683 |
@@ -27,7 +27,7 @@ |
||
27 | 27 | ) { |
28 | 28 | |
29 | 29 | // parsing configuration |
30 | - $this->configuration = new Configuration( DefaultConfiguration::get() ); |
|
30 | + $this->configuration = new Configuration(DefaultConfiguration::get()); |
|
31 | 31 | $this->configuration->merge($configuration); |
32 | 32 | |
33 | 33 | // fix the daemon start time |
@@ -14,24 +14,24 @@ |
||
14 | 14 | $chars = 60; |
15 | 15 | |
16 | 16 | // show the header |
17 | - $console->br()->border('-',$chars); |
|
17 | + $console->br()->border('-', $chars); |
|
18 | 18 | $console->bold()->flank('Extender execution summary'); |
19 | - $console->border('-',$chars); |
|
19 | + $console->border('-', $chars); |
|
20 | 20 | $console->out('Total run time: '.self::calculateRunTime($daemon->starttime)); |
21 | - $console->border('-',$chars); |
|
21 | + $console->border('-', $chars); |
|
22 | 22 | $padding = $console->padding(26); |
23 | - $padding->label('Total processed jobs')->result($daemon->completedjobs+$daemon->failedjobs); |
|
23 | + $padding->label('Total processed jobs')->result($daemon->completedjobs + $daemon->failedjobs); |
|
24 | 24 | $padding = $console->padding(30); |
25 | 25 | $padding->label('├─ Completed')->result('<light_green>'.$daemon->completedjobs.'</green>'); |
26 | 26 | $padding->label('└─ Failed')->result('<red>'.$daemon->failedjobs.'</red>'); |
27 | - $console->border('-',$chars); |
|
27 | + $console->border('-', $chars); |
|
28 | 28 | |
29 | 29 | } |
30 | 30 | |
31 | 31 | private static function calculateRunTime($starttime) { |
32 | 32 | |
33 | - $start_formatted = sprintf("%06d",($starttime - floor($starttime)) * 1000000); |
|
34 | - $start = new DateTime( date('Y-m-d H:i:s.'.$start_formatted, $starttime) ); |
|
33 | + $start_formatted = sprintf("%06d", ($starttime - floor($starttime)) * 1000000); |
|
34 | + $start = new DateTime(date('Y-m-d H:i:s.'.$start_formatted, $starttime)); |
|
35 | 35 | $end = new DateTime(); |
36 | 36 | |
37 | 37 | $diff = $end->diff($start); |
@@ -9,7 +9,7 @@ |
||
9 | 9 | |
10 | 10 | $daemon = $event->getDaemon(); |
11 | 11 | |
12 | - if ( $daemon->looplimit === $daemon->loopcount) { |
|
12 | + if ( $daemon->looplimit === $daemon->loopcount ) { |
|
13 | 13 | $daemon->logger->info('Stopping daemon due to loop limit ('.$daemon->looplimit.') reached'); |
14 | 14 | // $daemon->stop(); |
15 | 15 | $daemon->loopactive = false; |
@@ -14,10 +14,10 @@ |
||
14 | 14 | |
15 | 15 | if ( empty($jobs) ) return; |
16 | 16 | |
17 | - $console->border('-',30); |
|
17 | + $console->border('-', 30); |
|
18 | 18 | $console->bold()->green('Extender loop summary'); |
19 | 19 | $console->out("Loop duration: ".round($daemon->loopelapsed)); |
20 | - $console->border('-',30); |
|
20 | + $console->border('-', 30); |
|
21 | 21 | $console->out("Executed jobs: "); |
22 | 22 | $console->table($jobs); |
23 | 23 |