Reputation: 1942
I have a kotlin spring-boot application with jobrunr org.jobrunr:jobrunr-spring-boot-2-starter:6.1.1
. I would like to be able to catch cases when scheduled job has failed after all retries. Now, by default, information about such failed jobs is stored in table jobrunr_jobs
. But for me this is not a suitable option, because I only find out about such jobs when I look at this table myself, and not immediately as soon as it happens.
My custom ApplyStateFilter
:
@Component
class FailedStateFilter(
private val alertService: AlertService
) : ApplyStateFilter {
override fun onStateApplied(job: Job, oldState: JobState, newState: JobState) {
if (mustBeProcessed(job, newState)) {
alertService.send(job)
}
}
private fun mustBeProcessed(job: Job, newState: JobState) =
job.jobName == NOTIFICATION_JOB_NAME && newState is FailedState && newState.mustNotRetry()
}
JobRunr Documentation says:
A Job Filter can be used to extend the functionality of JobRunr with extra business processes when a job succeeds or fails. They also exist in the free version
But I don't understand how can I use my custom ApplyStateFilter
in the free version
Upvotes: 0
Views: 304
Reputation: 1106
Job Filters are not automatically registered when used with Spring integration. Here, the author of the library shows a way to configure filters using Fluent Java API.
I found even easier method for registering Spring managed Job Filter beans.
Just inject all the implementations of JobFilter
and add all of them using BackgroundJobServer
since it already comes as a Spring managed bean. Here is how I did it in java:
@Configuration
public class JobrunrConfig {
JobrunrConfig(BackgroundJobServer backgroundJobServer, List<? extends JobFilter> jobFilters) {
backgroundJobServer.getJobFilters().addAll(jobFilters);
}
}
Upvotes: 0