Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1433 from tomaszdurka/issue-1433
Browse files Browse the repository at this point in the history
Make _registerJobs protected
  • Loading branch information
tomaszdurka committed Oct 7, 2014
2 parents 665d45c + 062a132 commit 58c455d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
4 changes: 4 additions & 0 deletions library/CM/Jobdistribution/Cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ class CM_Jobdistribution_Cli extends CM_Cli_Runnable_Abstract {
*/
public function startWorker() {
$worker = new CM_Jobdistribution_JobWorker();
foreach (CM_Jobdistribution_Job_Abstract::getClassChildren() as $jobClassName) {
$job = new $jobClassName();
$worker->registerJob($job);
}
$worker->run();
}

Expand Down
15 changes: 7 additions & 8 deletions library/CM/Jobdistribution/JobWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ public function __construct() {
//use non-blocking IO mode to enable signal processing in worker processes as soon as libgearman/pecl gearman is fixed
//see https://bugs.php.net/bug.php?id=60764
//$this->_gearmanWorker->addOptions(GEARMAN_WORKER_NON_BLOCKING);
$this->_registerJobs();
}

/**
* @param CM_Jobdistribution_Job_Abstract $job
*/
public function registerJob(CM_Jobdistribution_Job_Abstract $job) {
$this->_gearmanWorker->addFunction(get_class($job), array($job, '__executeGearman'));
}

public function run() {
Expand Down Expand Up @@ -51,11 +57,4 @@ protected function _getGearmanWorker() {
}
return $this->_gearmanWorker;
}

private function _registerJobs() {
foreach (CM_Jobdistribution_Job_Abstract::getClassChildren() as $jobClassName) {
$job = new $jobClassName();
$this->_gearmanWorker->addFunction($jobClassName, array($job, '__executeGearman'));
}
}
}

0 comments on commit 58c455d

Please sign in to comment.