nestjs/schedule

Add Support/Workaround to Scope.REQUEST Injected Service (ScheduledService not working)

kuriel-trivu opened this issue · 1 comments

I'm submitting a...


[ ] Regression 
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

Scheduled Tasks not running when injected or nested service has @Injectable({ scope: Scope.REQUEST })

Expected behavior

Scheduled Tasks running normally.

Minimal reproduction of the problem with instructions

Step 1: Create a Service with:

@Injectable({ scope: Scope.REQUEST })
export class SomeService {}

Step 2: Inject SomeService into the Scheduled Service:

@Injectable()
export class ScheduledService {
  constructor(
    private readonly someService: SomeService,
  ) {
  }
}

What is the motivation / use case for changing the behavior?

If a service with Scope.REQUEST is not supported OK, but that should not stop Scheduled Services to work.

Environment


Nest version: 7.6.15

    "@nestjs/common": "7.6.15",
    "@nestjs/core": "7.6.15",
    "@nestjs/jwt": "7.2.0",
    "@nestjs/passport": "7.1.5",
    "@nestjs/platform-express": "7.6.15",
    "@nestjs/platform-socket.io": "7.6.15",
    "@nestjs/schedule": "0.4.3",
    "@nestjs/websockets": "7.6.15",
 
For Tooling issues:
- Node version: v12.20.0  
- Platform:  Mac 11.2.1 (20D74) 

Others:
Using Yarn.

Scheduled Tasks not running when injected or nested service has @Injectable({ scope: Scope.REQUEST })

This is expected. You should never use request-scoped providers in timers.