nyeholt / silverstripe-gearman

A basic integration with gearmand
6 stars 4 forks source link

Support for multiple machines #4

Open johannesx75 opened 8 years ago

johannesx75 commented 8 years ago

From what I can tell the gearman server config is currently hard coded to be localhost:4730 in multiple places. I would like to use this module (and silverstripe-queuedjobs) in a setup where we:

  1. have multiple SilverStripe instances running on different machines behind a load balancer acting as clients that submit jobs to the jobserver.
  2. have multiple SilverStripe instances running on different machines acting as workers that connect to the job server to work on those jobs

I guess the solution would be to move the server config to the config system / yml. Maybe allow to pass it as parameters to the runner script.

Is this correct and if yes would you be interested in a pull request for those changes?

nyeholt commented 8 years ago

From what I can tell the gearman server config is currently hard coded to be localhost:4730 in multiple places

On the job creation side of things, these are just the default settings; to change that, you can specify the alternatives via

Injector:
  GearmanService:
    host: myhostname
    port: 1234

As for running jobs, for your specific use-case, I'm not sure that either of the example *_runner.php scripts will do exactly what you want

In any case, it's likely you'll want to create your own runner.php script with appropriate config details for which gearman server to connect to for listening for jobs. The current scripts at present aren't really generic enough at present.

johannesx75 commented 8 years ago

Thanks, setting the server info via Injector works great.

The gearman_runner.php seems to work for my needs, if I change the $worker->addServer call to contain the server data.

I think it would be nice to pass the server data as parameters to the runner. I saw that you copy the first argument to the get parameter 'url' in line 47. Is there any reason for this?

johannesx75 commented 8 years ago

Just in case someone is looking for a way to do this...

I changed the gearman_runner.php to pull the gearman server address from the config as well:

$confLocator = Injector::inst()->getConfigLocator();
$serverConfig = $confLocator->locateConfigFor('GearmanService');

$worker = new \Net\Gearman\Worker();
$worker->addServer($serverConfig["properties"]["host"]);

In the config.yml the config needs to reside under properties:

Injector:
  GearmanService:
    properties:
      host: myhostname

Same could be done with the port, if needed. This way the same config works for gearman workers as for job creation.