Skip to main content

Managing a Job

The Schedule Plugin provides a set of methods that allow you to manage jobs that have been created using either decorators or the SchedulerService. You can use these methods to start, stop and delete jobs as needed.

Retrieving a Job​

If you want to retrieve a job that has been created using either decorators or the SchedulerService, you can use the getJob method of the SchedulerRegistry. This method allows you to retrieve a job by its name, which is a unique identifier for the job. The getJob method returns a JobDefinition object that contains information about the job, such as its name, schedule, etc.

The SchedulerRegistry is a service that is provided by the Schedule Plugin and can be injected into your classes using dependency injection. You can use the SchedulerRegistry to manage jobs that have been created using either decorators or the SchedulerService.

The SchedulerRegistry provides additional methods for managing jobs, such as getAllJobs or removeJob. If you want to stop or remove a job, you have to use the methods of the SchedulerRegistry. Please, check the API documentation for more information on the available methods and their usage.

Scheduler Service​

The SchedulerService provides the following methods for managing jobs:

  • startJob(job: string | JobDefinition): Promise<void>: Starts a job that has been created using the SchedulerService. You can use this method to start a job that has been stopped or to start a job that has been created but not yet started.
  • stopJob(job: string | JobDefinition): Promise<void>: Stops a job that is currently running. You can use this method to stop a job that is no longer needed or to temporarily pause a job.

SchedulerService offers more methods for managing jobs, such as isJobRunning or stopAllJobs. Please, check the API documentation for more information on the available methods and their usage.

Modifying a Job​

You can also modify a job that has been created using either decorators or the SchedulerService. To modify a job, you can use the update methods of each job definition. The update methods allow you to change the schedule (cron expression, interval duration, date, or timeout duration) of the job. The change will take effect in the next execution cycle, and the job will be rescheduled according to the new schedule.

If you want to start the new schedule immediately, you can stop the job and start it again using the stopJob and startJob methods of the SchedulerService. This will ensure that the job is executed according to the new schedule without waiting for the next execution cycle.