Appearance
Cronjob Entrypoint
path: /src/entrypoints/cronjob.ts
Usage
When you need a task to run at specific intervals or times, you can create a cronjob.
WARNING
Most of the time, you will not need to create a cronjob.
Always consider if a cronjob is the best solution for your use case.
INFO
Contact the DevOps team to deploy your cronjob to the Kubernetes cluster and provide them with:
- The cronjob type
- The schedule you want to use
Running locally
bash
pnpm start:dev cronjob -- <cronjob type>
Creating a cronjob
- Create the following folder and files under the dedicated module (
src/modules/<module>/cronjobs
)
├── src/
│ ├── modules/
│ │ └── module_x
│ │ ├──cronjobs
│ │ │ └── cronjob_type
│ │ │ ├── cronjob_type.module.ts
│ │ │ └── cronjob_type.use-case.ts
│ │ └── ...
│ └── ...
└── ...
- Implement the cronjob functionality
typescript
@Injectable()
export class CronjobTypeUseCase implements AbstractUseCase {
constructor() {}
async execute(): Promise<void> {
// ...
}
}
- Create the module
typescript
@Module({
imports: [
// Define necessary imports here
],
providers: [CronjobTypeUseCase],
exports: [CronjobTypeUseCase],
})
export class ImportTypesenseModule {}
- Define the cronjob type
- Within
src/modules/cronjobs/enums/cronjob-type.enum.ts
add the new cronjob. - Link the module and use-case of this cronjob within
src/modules/cronjobs/cronjob-type.mapping.ts
.