martinweiler commented on code in PR #2952: URL: https://github.com/apache/incubator-kie-tools/pull/2952#discussion_r1977921145
########## examples/process-business-calendar/README.md: ########## @@ -330,7 +330,72 @@ curl -X GET http://localhost:8080/BusinessCalendarCreditBill \ - On next business day, timer will resume at the beginning of the next working hour/day, after the non-working hour/holiday has ended. The timer is set to fire after one second of active business time. --- +## Custom Business Calendar Flexibility +**Why Create a Custom Business Calendar?** +- Custom schedules that differ from the default behavior. +- Modify, delay, or override time calculations. +- Implement custom business logic for when tasks should be triggered. + +This guide explains how to implement a custom business calendar allowing full flexibility. + +--- + +### Creating a Custom Business Calendar + +- By default, calendar.properties is used to configure default business calendar. +- If a custom business calendar has to be implemented, calendar.properties should NOT exist. Instead, add the following property to application.properties: ```kogito.processes.businessCalendar=org.kie.kogito.calendar.CustomCalendar``` + +**Steps** +1. **Navigate to**: *examples/process-business-calendar/src/main/java/org/kie/kogito/calendar (create the org/kie/kogito/calendar directory if it does not exist)* +2. **Create a new custom business calendar class** (e.g., CustomCalendar.java). +3. Ensure it implements the BusinessCalendar interface.The implementation should be a concrete class(not an interface or abstract class). +4. Set the property ```kogito.processes.businessCalendar=org.kie.kogito.calendar.custom.CustomCalendar``` in application.properties to the fully qualified class name of the custom business calendar. +5. To test the created custom business calendar with property set in application.properties, calendar.properties should not exist. + + + +**Implement your custom business logic** +- For demonstration, an example is provided below. However, you are free to define your own logic. + +```java +package org.kie.kogito.calendar.custom; + +import java.util.*; +import org.kie.kogito.calendar.BusinessCalendar; + +/** + * Custom Business Calendar Example. + * Modify this class to implement your own scheduling logic. + */ +public class CustomCalendar implements BusinessCalendar { + + @Override + public long calculateBusinessTimeAsDuration(String timeExpression) { + // Implement custom logic to calculate business time duration + return 0; Review Comment: Two suggestions to improve this: 1. Add a note that the returned long is in ms 2. Return at least 1000 (ms) or longer When returning 0 - the timer will be executed too soon: ``` 2025-03-03 10:39:50,443 INFO [org.kie.kog.ser.job.imp.SignalProcessInstanceOnExpiredTimer] (executor-thread-2) Skipping Job e7457ab4-ae78-4276-a39e-01f27dbb0442. There is no process for pid 2915b32d-4d69-4382-8016-0ab90c3df3c1 ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
