Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for multiple machines #4

Open
johannesx75 opened this issue Jan 12, 2016 · 3 comments
Open

Support for multiple machines #4

johannesx75 opened this issue Jan 12, 2016 · 3 comments

Comments

@johannesx75
Copy link

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
Copy link
Owner

nyeholt commented Jan 13, 2016

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

  • the reflected_runner.php assumes the uses some parameters passed in the job to determine which SS instance triggered the job. This is more useful for a shared server scenario where you have multiple discrete instances (ie with separate codebases/DBs) all sharing the same local gearman instance
  • the gearman_runner.php is probably closer to your needs in that it will execute in the context of a SilverStripe instance and grab jobs from any gearman server, but be aware that the way it's written it'll grab any job, regardless of the source SS instance. If in the scenario you describe those source instances are just load balanced replicas of the same 'discrete instance' (ie same DB) that won't be an issue.

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
Copy link
Author

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
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants