Skip to content

Commit

Permalink
Expose auto load path configuration for child execured process.
Browse files Browse the repository at this point in the history
  • Loading branch information
steven.chiu committed Jun 5, 2019
1 parent e4c9990 commit 63f6d73
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
8 changes: 3 additions & 5 deletions src/JobScheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

namespace TimeWorker;

include_once __DIR__.'/../vendor/autoload.php';
include_once __DIR__ . '/RedisFactory.php';

use React\EventLoop\Factory;

class JobScheduler
Expand Down Expand Up @@ -38,7 +35,8 @@ public function __construct(
$port = 6379,
$db = 0,
$executableTime = self::EXECUTABLE_TIME,
$pollingInterval = self::POLLING_INTERVAL
$pollingInterval = self::POLLING_INTERVAL,
$autoloadPath = __DIR__."/../../../../vendor/autoload.php"
) {
$this->redisConf['host'] = $host;
$this->redisConf['port'] = $port;
Expand All @@ -48,7 +46,7 @@ public function __construct(
$this->subPattern = '__keyspace@' . $db . '__:';
$this->executableTime = $executableTime;
$this->pollingInterval = $pollingInterval;
$this->forkChildCmd = "php -r \"include '" . __FILE__ . "'; TimeWorker\JobScheduler::fork(1, '$host', $port, $db);\"";
$this->forkChildCmd = "php -r \"include_once '$autoloadPath'; include '".__DIR__."/RedisFactory.php'; use TimeWorker\JobScheduler; TimeWorker\JobScheduler::fork(1, '$host', $port, $db);\"";

$looper = Factory::create();
$this->looper = $looper;
Expand Down
2 changes: 1 addition & 1 deletion test/job_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function init($redisConf, $isJobSubmitter = false)
{
global $db;
try {
$scheduler = new JobScheduler(0, $redisConf['host'], $redisConf['port'], $db, 180, 30);
$scheduler = new JobScheduler(0, $redisConf['host'], $redisConf['port'], $db, 180, 30, __DIR__."/../vendor/autoload.php");
testAddJob($redisConf);
$scheduler->getLooper()->addPeriodicTimer(20, function () use ($redisConf) {
testAddJob($redisConf);
Expand Down

0 comments on commit 63f6d73

Please sign in to comment.