kurtzl / nestjs-temporal Goto Github PK
View Code? Open in Web Editor NEWTemporal plugin for nestjs framework
License: MIT License
Temporal plugin for nestjs framework
License: MIT License
Hey.
First of all thanks a lot for this module.
It seems like there is an issue when trying to inject / import other services to this module in order to be able to use them in activities (Activity should be able to use a service -> which has a repository injected to it -> etc...)
Any suggestion?
Thanks
Planning to use this in our NestJS based project however we are on v9 and this is supporting up until v8. Wondering if this repo will be maintained and upgraded to v9?
Hello mate, hope you're doing well
I'm creating unit tests for my services and I need the getQueueToken function from this lib in order to mock the WorkflowClient provider with @nestjs/testing lib, can you export that function in a new release of this package please? ๐
Thanks for your help!
We are observing following dependency vuln via dependabot. This is a critical vuln
Dependabot cannot update parse-url to a non-vulnerable version
The latest possible version that can be installed is 6.0.5 because of the following conflicting dependencies:
[email protected] requires parse-url@^6.0.0 via a transitive dependency on [email protected]
No patched version available for parse-url
The earliest fixed version is 8.1.0.
ValidationPipe support might save many programs time since nestjs has already validation pipe mechanism.
My suggestion is to add an optional decorator for activity input for example:
@Activity()
async submitOrder(@Payload() order: Order) {
}
And in cast this input param Payload exists add class-validator validation to the function before injecting it to the worker.
Or any other idea.
In the activities part it's a bit more complicated not sure how.
If you find this idea relevant I will be glad to contribute
Hi, are you open to accepting pull requests? Have an idea for a dynamically created activity name
I'm trying to test your plugin but of some reason I keep getting this error. Any ideas?
Thanks
RB
Debugger listening on ws://127.0.0.1:36729/7085afc2-535f-430f-94e8-d9f561398b9c
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
[Nest] 3141873 - 05/24/2022, 2:08:38 PM LOG [NestFactory] Starting Nest application...
[Nest] 3141873 - 05/24/2022, 2:08:38 PM LOG [InstanceLoader] AppModule dependencies initialized +60ms
[Nest] 3141873 - 05/24/2022, 2:08:38 PM LOG [InstanceLoader] TemporalModule dependencies initialized +0ms
[Nest] 3141873 - 05/24/2022, 2:08:38 PM LOG [InstanceLoader] TemporalModule dependencies initialized +0ms
[Nest] 3141873 - 05/24/2022, 2:08:38 PM LOG [InstanceLoader] DiscoveryModule dependencies initialized +1ms
[Nest] 3141873 - 05/24/2022, 2:08:38 PM LOG [InstanceLoader] TemporalModule dependencies initialized +0ms
/home/rbialek/nest-temporal/node_modules/nestjs-temporal/dist/temporal.explorer.js:55
yield worker_1.Core.install(coreConfig);
^
TypeError: Cannot read properties of undefined (reading 'install')
at TemporalExplorer. (/home/rbialek/nest-temporal/node_modules/nestjs-temporal/dist/temporal.explorer.js:55:37)
at Generator.next ()
at fulfilled (/home/rbialek/nest-temporal/node_modules/nestjs-temporal/dist/temporal.explorer.js:14:58)
Waiting for the debugger to disconnect...
Hello,
I'm currently facing an issue while trying to run unit tests with Jest for Temporal activities in a NestJS application using the nestjs-temporal
module. When running my tests, I get the following error:
FAIL src/temporal/activities/blackjack.activity.spec.ts
โ Test suite failed to run
duplicate name 'ActivityHeartbeat' in Namespace coresdk
3 | import { Injector } from '@nestjs/core/injector/injector';
4 | import { InstanceWrapper } from '@nestjs/core/injector/instance-wrapper';
> 5 | import { NativeConnection, NativeConnectionOptions, Runtime, RuntimeOptions, Worker, WorkerOptions } from '@temporalio/worker';
| ^
6 |
7 | import { TEMPORAL_CONNECTION_CONFIG, TEMPORAL_CORE_CONFIG, TEMPORAL_WORKER_CONFIG } from './temporal.constants';
8 | import { TemporalMetadataAccessor } from './temporal-metadata.accessors';
at Namespace.add (node_modules/protobufjs/src/namespace.js:239:23)
at Root.add (node_modules/protobufjs/src/namespace.js:232:28)
at Root.addJSON (node_modules/protobufjs/src/namespace.js:172:16)
at Object.<anonymous> (node_modules/@temporalio/common/node_modules/@temporalio/proto/protos/json-module.js:7:2)
at Object.<anonymous> (node_modules/@temporalio/common/node_modules/@temporalio/proto/protos/root.js:8:23)
at Object.<anonymous> (node_modules/@temporalio/common/node_modules/@temporalio/proto/protos/index.js:1:100)
at Object.<anonymous> (node_modules/@temporalio/common/src/proto-utils.ts:2:1)
at Object.<anonymous> (node_modules/@temporalio/worker/src/worker.ts:52:1)
at Object.<anonymous> (node_modules/@temporalio/worker/src/debug-replayer/index.ts:4:1)
at Object.<anonymous> (node_modules/@temporalio/worker/src/index.ts:25:1)
at Object.<anonymous> (src/libs/nestjs-temporal/temporal.explorer.ts:5:1)
at Object.<anonymous> (src/libs/nestjs-temporal/temporal.module.ts:6:1)
at Object.<anonymous> (src/libs/nestjs-temporal/index.ts:1:1)
at Object.<anonymous> (src/temporal/activities/blackjack.activity.ts:12:1)
at Object.<anonymous> (src/temporal/activities/blackjack.activity.spec.ts:5:1)
This seems to suggest that the ActivityHeartbeat
message is being defined more than once in the same namespace. Is the NestJS Temporal module causing this conflict?
Here's the context for when the issue arises:
I have an activity in my application:
@Activity()
async verifyLimit(bet: BlackjackBetSlip): Promise<boolean> {
...
}
And I'm trying to write a Jest test for it, like so:
import { MockActivityEnvironment } from '@temporalio/testing';
import { BlackjackBetSlip } from '../types/blackjack';
import { Currency } from '../types/roulette';
import { Decimal } from '@prisma/client/runtime';
import assert from 'assert';
import { BlackjackActivity } from './blackjack.activity';
const { verifyLimit } = BlackjackActivity;
const env = new MockActivityEnvironment();
describe('verifyLimit activity', () => {
it('should return true for valid bet', async () => {
const bet: BlackjackBetSlip = {
amount: new Decimal(1000),
currency: Currency.NILET,
gameLogId: 'test',
idempotencyKey: 'test',
userId: 'test',
};
const result = await env.run(verifyLimit, bet);
assert.equal(result, true);
});
});
Is there a known workaround, or could this be a bug or incompatibility in the 'nestjs-temporal' module itself?
I have the following code, which is quite similar to the example code provided for manually creating a connection.
TemporalModule.registerClientAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: async (config: ConfigService) => {
const temporalHost = config.get('TEMPORAL_URL', 'localhost:7233')
const connection = await Connection.connect({
address: temporalHost
})
return {
connection
}
}
})
However I can't seem to make it work, because I get the following error:
Error: Nest can't resolve dependencies of the TemporalAsyncQueue_default (?). Please make sure that the argument ConfigService at index [0] is available in the TemporalModule context.
Potential solutions:
- If ConfigService is a provider, is it part of the current TemporalModule?
- If ConfigService is exported from a separate @Module, is that module imported within TemporalModule?
@Module({
imports: [ /* the Module containing ConfigService */ ]
})
at Injector.lookupComponentInParentModules (C:\Users\koppa.peter\Desktop\mti-hirugynokseg\src\sites\node_modules\.pnpm\@[email protected]_@[email protected]_@[email protected][email protected][email protected]\node_modules\@nestjs\core\injector\injector.js:241:19)
at Injector.resolveComponentInstance (C:\Users\koppa.peter\Desktop\mti-hirugynokseg\src\sites\node_modules\.pnpm\@[email protected]_@[email protected]_@[email protected][email protected][email protected]\node_modules\@nestjs\core\injector\injector.js:194:33)
at resolveParam (C:\Users\koppa.peter\Desktop\mti-hirugynokseg\src\sites\node_modules\.pnpm\@[email protected]_@[email protected]_@[email protected][email protected][email protected]\node_modules\@nestjs\core\injector\injector.js:116:38)
at async Promise.all (index 0)
at Injector.resolveConstructorParams (C:\Users\koppa.peter\Desktop\mti-hirugynokseg\src\sites\node_modules\.pnpm\@[email protected]_@[email protected]_@[email protected][email protected][email protected]\node_modules\@nestjs\core\injector\injector.js:131:27)
at Injector.loadInstance (C:\Users\koppa.peter\Desktop\mti-hirugynokseg\src\sites\node_modules\.pnpm\@[email protected]_@[email protected]_@[email protected][email protected][email protected]\node_modules\@nestjs\core\injector\injector.js:57:13)
at Injector.loadProvider (C:\Users\koppa.peter\Desktop\mti-hirugynokseg\src\sites\node_modules\.pnpm\@[email protected]_@[email protected]_@[email protected][email protected][email protected]\node_modules\@nestjs\core\injector\injector.js:84:9)
at async Promise.all (index 3)
at InstanceLoader.createInstancesOfProviders (C:\Users\koppa.peter\Desktop\mti-hirugynokseg\src\sites\node_modules\.pnpm\@[email protected]_@[email protected]_@[email protected][email protected][email protected]\node_modules\@nestjs\core\injector\instance-loader.js:44:9)
at C:\Users\koppa.peter\Desktop\mti-hirugynokseg\src\sites\node_modules\.pnpm\@[email protected]_@[email protected]_@[email protected][email protected][email protected]\node_modules\@nestjs\core\injector\instance-loader.js:29:13
I tried to look into the source code and TemporalModule.registerClientAsync
and the functions that invokes doesn't seem to do anything with the imports of the provided object.
I am migrating a service to use NestJS. The workers share a connection and client. Shutting down the service results in the error below. The client is most likely being shutdown before the worker. Admittedly, this is a problem of my own making; but, it would be ideal if this error were squashed and logged, rather than bubbling up.
[17:00:59.990] ERROR (49994): Error happened during shutdown
context: "NestApplicationContext"
err: {
"type": "Error",
"message": "Error happened during shutdown",
"stack":
IllegalStateError: Not running
at Worker.shutdown (/Users/clintonb/vori/backend/node_modules/@temporalio/worker/src/worker.ts:755:13)
at TemporalExplorer.onModuleDestroy (/Users/clintonb/vori/backend/node_modules/nestjs-temporal/dist/temporal.explorer.js:49:68)
at MapIterator.iteratee (/Users/clintonb/vori/backend/node_modules/@nestjs/core/hooks/on-module-destroy.hook.js:22:43)
at MapIterator.next (/Users/clintonb/vori/backend/node_modules/iterare/src/map.ts:9:39)
at IteratorWithOperators.next (/Users/clintonb/vori/backend/node_modules/iterare/src/iterate.ts:19:28)
at Function.from (<anonymous>)
at IteratorWithOperators.toArray (/Users/clintonb/vori/backend/node_modules/iterare/src/iterate.ts:227:22)
at callOperator (/Users/clintonb/vori/backend/node_modules/@nestjs/core/hooks/on-module-destroy.hook.js:23:10)
at callModuleDestroyHook (/Users/clintonb/vori/backend/node_modules/@nestjs/core/hooks/on-module-destroy.hook.js:43:23)
at NestApplication.callDestroyHook (/Users/clintonb/vori/backend/node_modules/@nestjs/core/nest-application-context.js:234:53)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async process.cleanup (/Users/clintonb/vori/backend/node_modules/@nestjs/core/nest-application-context.js:188:17)
}
nestjs-temporal/lib/temporal.explorer.ts
Line 53 in 4b0b0c5
Seems like temporalio's typescript sdk now has an official release in 1.0.0 (https://github.com/temporalio/sdk-typescript/tags). Are there plans to upgrade this package to support that? Tried upgrading the package myself in a fork, but running into some issues with the client connection.
https://github.com/KurtzL/nestjs-temporal/blob/main/lib/decorators/workflow.decorator.ts
I've been trying to leverage @workflows and @WorkflowMethod with no success. The bundleWorkflowCode and the workflowsPath configuration options for the registerWorkerAsync won't work. I get a lot of webpack errors. Are these decorators meant to be used?
The only reason I care is that I need to access some provided services and I wanted to inject them into a class and using a straight function for a workflow definition is problematic.
is there any complete example using this module?
@KurtzL ?
@KurtzL can you release a new version with the latest changes, please?
Hi, after the Temporal version upgrade, started receiving two below errors. Please let know the cause and how to fix it.
2022-11-30T09:29:38.286254Z ERROR temporal_sdk_core::worker::workflow::managed_run: Error in run machines, error: RunUpdateErr(Nondeterminism("No command scheduled for event HistoryEvent(id: 6, Some(ActivityTaskScheduled))"))
2022-11-30T09:29:40.252688Z ERROR temporal_sdk_core::worker::workflow::managed_run: Error in run machines, error: RunUpdateErr(Nondeterminism("Activity machine does not handle this event: HistoryEvent(id: 5, Some(TimerStarted))"))
Everything starts fine on the first run, but when changing code and hot reloading is triggered, the worker seems to gracefully shutdown successfully, but upon restarting, the process complains the default 3000 port is already in use(I assume the one nestjs is listening. Now, I have a feeling this is because the worker is spawned as a child process, and it tries to bind to the same address. Maybe I'm wrong, but I can't seem to find a workaround. Any ideas would be appreciated.
Running into the following error when trying to run your project, installed via npm version 0.0.5 https://www.npmjs.com/package/nestjs-temporal
It seems that it thinks the core package from @temporal/worker is undefined
/node_modules/nestjs-temporal/dist/temporal.explorer.js:55
yield worker_1.Core.install(coreConfig);
^
TypeError: Cannot read properties of undefined (reading 'install')
at TemporalExplorer.<anonymous> (/node_modules/nestjs-temporal/dist/temporal.explorer.js:55:37)
at Generator.next (<anonymous>)
at fulfilled (/node_modules/nestjs-temporal/dist/temporal.explorer.js:14:58)
Also, how does this package work, does it boot up a worker service that listens on the same process as the controllers? Trying to implement this in a monolith where there are two separate apps, one that deals with API endpoints (controller), and the worker that solely runs workflows and activities
In the peer dependencies it specifies nest v8 as supported. However it is using ConfigurableModuleBuilder from @nestjs/common which wasn't available until v9.
The postinstall
script is being run after the package is installed. This works with yarn, but fails for pnpm. I would expect the compiled dist
directory to be included in the download from NPM, not to require compilation post-download.
Consider the following:
dist
in the package uploaded to NPM.postinstall
script.A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.