#Cannot register cron job "ClassName@methodName" because it is defined in a non static provider

15 messages · Page 1 of 1 (latest)

undone marsh
#

import { Injectable } from '@nestjs/common';
import { Cron } from '@nestjs/schedule';
// other imports

@Injectable()
export class ClassNameJob {
constructor(private readonly xxxService: XxxService) {
}
@Cron(CronConstants.AT_EVERY_2TH_MINUTE)
async methodName(userId?: number) {
// ... code
}
}

Need some help with, I didn't find the solution yet. Will be helpful if someone had similar issue and solve it.

tulip spire
#

Is the xxxService request-scoped?

undone marsh
tulip spire
#

I see there's an argument userId?: number on the methodName - that could be the issue, since the cron won't know what to provide.

undone marsh
#

no, forget that userId: number, that is just a ex I found on the github on search for my issue

#

this is my code

ashen tide
#

What does V2BookingService inject?

undone marsh
#

doesn't ineject anything

ashen tide
#

Can you show the class/constructor?

undone marsh
ashen tide
#

So, yes, it does inject something. A lot of somethings. BookingRepository, PassengerRepository, V2ProviderAPI,... etc. If any of those are REQUEST scoped,say, because it's a multi-tenant database that changes connection per request, or any other reason, then the CronJobService will also be REQUEST scoped

undone marsh
#

when you said inject I was thought about is putting scope in "@Injectable()"

Yes, if one of them has @Injectable({ scope: Scope.REQUEST }) what should be the solutions ?

ashen tide
#

Find a way to not require the V2BookingService in the CronJobService

undone marsh
#

Thank you 👌🏾, I'll try to do that.