#Running 1-off task in a Kubernetes Cronjob - How to exit?

6 messages · Page 1 of 1 (latest)

onyx harness
#

Hello!
I wanted to know what is the best practice to start a nestJS app that schedule items to a queue, and then exit right away once done.

Is it through the main.ts ? You await a module/service and then exit when it is done?
Or do you use a package and convert it to a CLI app? like https://github.com/jmcdo29/nest-commander?

silk tusk
#

I would either use NestFactory.createApplicationContext to avoid any HTTP engine, or just use nest-commander for the CLI app

onyx harness
#

But imagine this one-off job takes 1h to run, it might need HTTP engine to act as a health probe, right?
Or would you skip health probes in such context?

silk tusk
#

Are you expecting to make health probe checks against one-off tasks?

onyx harness
#

Well this one should last few sec, but in the future we might get longer tasks, so I wonder what's the best practice with HTTP frameworks like Nest 🙂

steel cloak
#

Hey! For long running processes that will benefit from health probe you can require the service from main.ts with app.get({Service}) and start it directly. Then just wait for the promise to resolve. and when that's done you can close the app with await app.close().