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

feat(geoprocessing): allow workers to use di #202

Merged
merged 2 commits into from
May 24, 2021

Conversation

kgajowy
Copy link
Contributor

@kgajowy kgajowy commented May 21, 2021

Substitute this line for a meaningful title for your changes

Overview

Please write a description. If the PR is hard to understand, provide a quick explanation of the code.

Designs

Link to the related design prototypes (if applicable)

Testing instructions

Please explain how to test the PR: ID of a dataset, steps to reach the feature, etc.

Feature relevant tickets

Link to the related task manager tickets


Checklist before submitting

  • Meaningful commits and code rebased on develop.
  • If this PR adds feature that should be tested for regressions when
    deploying to staging/production, please add brief testing instructions
    to the deploy checklist (docs/deployment-checklist.md)
  • Update CHANGELOG file

@vercel
Copy link

vercel bot commented May 21, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployments, click below or on the icon next to each commit.

marxan-storybook – ./app

🔍 Inspect: https://vercel.com/vizzuality1/marxan-storybook/6wNLUw7ZWGt2iupUu9NYPV9rV5zK
✅ Preview: https://marxan-storybook-git-geoprocessing-feat-workers-di-vizzuality1.vercel.app

marxan – ./app

🔍 Inspect: https://vercel.com/vizzuality1/marxan/BYEJ1Qwec7173sxau8ZwdNDr4NQg
✅ Preview: https://marxan-git-geoprocessing-feat-workers-di-vizzuality1.vercel.app

@kgajowy
Copy link
Contributor Author

kgajowy commented May 21, 2021

Thanks @Dyostiq for helping out with this one!

Comment on lines 21 to 26
this._worker = new Worker<Input, Output>(
queueName,
(job: Job) => processor.process(job),
this.config.redis,
);
return this._worker as Worker<Input, Output>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this._worker = new Worker<Input, Output>(
queueName,
(job: Job) => processor.process(job),
this.config.redis,
);
return this._worker as Worker<Input, Output>;
const worker = new Worker<Input, Output>(
queueName,
(job: Job) => processor.process(job),
this.config.redis,
);
this._worker = worker;
return worker;

no cast needed :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in d4a3c87

const addValue = 3;

/**
* This tests USES redis to ensure that workers module works with full flow
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

Comment on lines 9 to 26
export class WorkerResolver implements OnModuleDestroy {
private _worker?: Worker;

constructor(private readonly config: Config) {}

wrap<Input, Output>(
queueName: string,
processor: WorkerProcessor<Input, Output>,
): Worker<Input, Output> {
if (this._worker) {
throw new Error('Worker is already created!');
}
this._worker = new Worker<Input, Output>(
queueName,
(job: Job) => processor.process(job),
this.config.redis,
);
return this._worker as Worker<Input, Output>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the instance is disposable, and I am not sure if it's a wrapper, or it is a resolver (the naming is mixed in the PR a bit), I'd call it a builder, as builders have a single-use nature and shouldn't be reused after build.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in d4a3c87

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

Successfully merging this pull request may close these issues.

3 participants