SORMAS-Project icon indicating copy to clipboard operation
SORMAS-Project copied to clipboard

CronService: Improve failsafe quality and logging [3]

Open mario-kuehne opened this issue 2 years ago • 1 comments

Problem Description

The CronService (CronService.java) triggers different methods that might fail and throw exceptions. If an exception is thrown the method does not get scheduled again. Currently a server restart is necessary to achieve that the schedule for that method gets triggered again.

Proposed Change

  • Encapsulate every interior of every CronService method (~17 methods) as a CronJob subclass as shown in this PoC: 8e56b0afe4fe5a0eb9ec36abdae9f35041564ee3 The PoC is partly in german, translation needed.
  • Remove partly existing logging that is now done by CronJob per default.
  • Let more backend methods return the number of processed elements (Integer)?

Acceptance Criteria

Uncaught exceptions must not influence the schedule.

Implementation Details

  • See PoC: 8e56b0afe4fe5a0eb9ec36abdae9f35041564ee3

Additional Information

  • ~~Investigation necessary: Whole CronService impacted or just the scheduled method that throws an exception?~~ Ticket refined by @StefanKock

mario-kuehne avatar Apr 20 '22 09:04 mario-kuehne

~~Investigation~~ Known architecture: The timer for a @Schedule method that fails (twice) gets automatically explunged. A workaround pattern is known: You have to annotate the called ejb method with @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) and catch all RuntimeExceptions. In other products we use injectable Job instances (superclass that does a lot of boilerplate code, also includes logging and checking if the job is activated) per automatic action that is suppose to happen.

StefanKock avatar May 11 '22 11:05 StefanKock