Hey, just found pulse today and wanted to replace our agenda jobs.
In our current implementation we use a custom agenda service to fulfill our needs, for example prefixed job names for different environments (mainly for development, so every developer executes his own jobs while running on the same dev-db)
As i cant prefix the jobs in the pulse decorator with a dynamic variable from a service, i thought it might be a solution to have a collection per environment instead.
I use following setup:
// app.module.ts
// ...
@Module({
imports: [
ConfigModule.forRoot({
cache: true,
envFilePath: ['.env.development.local'],
}),
DatabaseModule,
PulseModule.forRootAsync({
imports: [DatabaseModule],
useClass: PulseProvider,
}),
PulseModule.registerQueueAsync('pulse-default-queue', PulseDefaultFactory),
//...
],
controllers: [AppController],
providers: [PulseProvider],
})
export class AppModule {}
// PulseProvider
@Injectable()
export class PulseProvider implements PulseConfigFactory<PulseModuleConfig> {
constructor(
private readonly mongoConnectionService: MongoConnectionService,
private readonly runtimeConfigService: RuntimeConfigService,
) {}
createPulseConfig(): PulseConfig | Promise<PulseConfig> {
const environmentLabel = this.runtimeConfigService.envLabel;
const appName = this.runtimeConfigService.get<string>(
'name',
defaultAppName,
);
return {
// FIXME try to remove any when mongo driver is updated
mongo: this.mongoConnectionService.getClient()?.db() as any,
name: appName + '@' + environmentLabel,
};
}
}
export const PulseDefaultFactory = {
imports: [DatabaseModule],
useFactory: (
runtimeConfigService: RuntimeConfigService,
): PulseQueueConfig | Promise<PulseQueueConfig> => {
const environmentLabel = runtimeConfigService.envLabel;
const collectionName = `pulse-${environmentLabel}`;
return {
collection: collectionName,
} as PulseQueueConfig;
},
inject: [RuntimeConfigService],
} as PulseModuleAsyncConfig<PulseQueueConfig>;
And then i have another Module where i added a provider to test pulse
// mail.processor.ts
import { Every, Queue } from '@pulsecron/nestjs-pulse';
import { Job } from '@pulsecron/pulse';
@Queue('pulse-default-queue')
export class MailQueueProcessor {
protected n = 'nt';
@Every({ name: 'testPulseEvery', interval: '10 seconds', })
async pulseEveryTest(job: Job) {
console.log(job);
}
}
And now comes the problem: The collection is created with the expected name, the job is also added as expected but its not executed.
I have tried to add the PulseModule.registerQueueAsync('pulse-default-queue', PulseDefaultFactory) to the module.import where the provider is located but it doesnt change anything. Only if i register without the factory the jobs get executed but then i cant divide jobs between environments (developer sessions)
Any idea, or hint how i could fix that?
A prefix for jobs set in the PulseProvider would also help :D
Hey, just found pulse today and wanted to replace our agenda jobs.
In our current implementation we use a custom agenda service to fulfill our needs, for example prefixed job names for different environments (mainly for development, so every developer executes his own jobs while running on the same dev-db)
As i cant prefix the jobs in the pulse decorator with a dynamic variable from a service, i thought it might be a solution to have a collection per environment instead.
I use following setup:
And then i have another Module where i added a provider to test pulse
And now comes the problem: The collection is created with the expected name, the job is also added as expected but its not executed.
I have tried to add the
PulseModule.registerQueueAsync('pulse-default-queue', PulseDefaultFactory)to the module.import where the provider is located but it doesnt change anything. Only if i register without the factory the jobs get executed but then i cant divide jobs between environments (developer sessions)Any idea, or hint how i could fix that?
A prefix for jobs set in the PulseProvider would also help :D