I have a Spring Boot application that uses the JobRunr library to run a set of background jobs. The application has no REST endpoints or any external-facing features. The primary job is a recurring job (R), which triggers several fire-and-forget jobs (A, B, and C), which in turn trigger another set of fire-and-forget jobs (E, F, and G).
While the application is running, I'm encountering exceptions with job E. Rather than catching the exceptions, I'm simply throwing them back as jobrunr documentation suggests. However, all jobs (R, A, and E) are reported as succeeded, despite the exception with job E. In fact, I expected job E to be in the failed state.
Has anyone else experienced a similar issue or have any insight into what might be causing this behavior?
I am enqueuing the recurring job as
@SpringBootApplication
public class NotificationApplication {
public static void main(String[] args) {
SpringApplication.run(NotificationApplication.class, args);
}
@Bean
public CommandLineRunner demo(RecurringBackGroundJobService service) {
return (args) -> {
BackgroundJob.scheduleRecurrently(
"generate-and-send-notification-emails",
Cron.every5minutes(),
RecurringBackGroundJobService::getNotificationsAndProcess
);
Thread.currentThread().join();
};
}
The recurring job looks like,
@Service
public class RecurringBackGroundJobService {
@Autowired
private NotificationService notificationQueueService;
@Transactional(readOnly = true)
@Job(name = "The main recurring job spawning all the background jobs to send out emails")
public void getNotificationsAndProcess() {
Stream<Long> organizationHavingPendingNotifications =
notificationQueueService.findDistinctOrganizationNotificationsWithDeliverStatus(Constants.PENDING);
BackgroundJob.<TemplateSegregationBackGroundJob, Long>enqueue(organizationHavingPendingNotifications,
(fireAndForgetBackGroundJobService, organizationId) ->
fireAndForgetBackGroundJobService.segregateTemplateLevel(organizationId));
}
}
The first layer of fire and forget job looks like
@Service
public class TemplateSegregationBackGroundJob {
@Autowired
private NotificationService notificationQueueService;
@Transactional(readOnly = true)
@Job(name = "Segregate the notifications as templates for organization/user with id: %0")
public void segregateTemplateLevel(Long organizationId) throws Exception {
final Stream<NotificationTemplate> pendingTemplatesOfOrganization =
notificationQueueService.findDistinctTemplatesOfOrganizationWithDeliverStatus(organizationId,Constants.PENDING);
BackgroundJob.<EmailServiceBackgroundJob, NotificationTemplate>
enqueue(pendingTemplatesOfOrganization, (emailServiceBackgroundJob, notificationTemplate) ->
emailServiceBackgroundJob.generateAndSendEmail(notificationTemplate, organizationId));
}
}
Now coming to the last layer, The main job, where I have all the logic and there I am encountering exceptions.
@Job(name = "Generate and send notification email of type: %0 for organization/user: %1")
public void generateAndSendEmail(NotificationTemplate notificationTemplate, Long organizationId) throws Exception {
// First of all get the processed email template from liferay API
// exception
}