Class ScheduledJobProcessingUtil

java.lang.Object
com.broadleafcommerce.common.messaging.util.scheduledjob.ScheduledJobProcessingUtil

public class ScheduledJobProcessingUtil extends Object
A utility class to execute a scheduled job while sending ScheduledJobStartedEvent and ScheduledJobCompletedEvent to facilitate tracking scheduled job execution details.
Author:
Sunny Yu
  • Constructor Details

    • ScheduledJobProcessingUtil

      public ScheduledJobProcessingUtil()
  • Method Details

    • executeJobWithTrackingExecutionDetails

      public static void executeJobWithTrackingExecutionDetails(@NonNull @NonNull ScheduledJobRef jobRef, @NonNull @NonNull Consumer<org.springframework.messaging.Message<?>> jobStartedMessageSender, @NonNull @NonNull Consumer<org.springframework.messaging.Message<?>> jobCompletedMessageSender, @NonNull @NonNull Consumer<ScheduledJobRef> scheduledJobExecutor)
      Executes the scheduled job using the given scheduledJobExecutor with the ability to track its execution details by sending the ScheduledJobStartedEvent and ScheduledJobCompletedEvent.
      Parameters:
      jobRef - the ScheduledJobRef for the scheduled job that is being executed
      jobStartedMessageSender - the message sender used to send a ScheduledJobStartedEvent. This should be a Spring Cloud message producer that takes in a Message.
      jobCompletedMessageSender - the message sender used to send a ScheduledJobCompletedEvent. This should be a Spring Cloud message producer that takes in a Message.
      scheduledJobExecutor - the Consumer<ScheduledJobRef> that is used to execute the scheduled job
    • sendScheduledJobStartedEventMessageIfNeeded

      public static void sendScheduledJobStartedEventMessageIfNeeded(@NonNull @NonNull ScheduledJobRef jobRef, @NonNull @NonNull Consumer<org.springframework.messaging.Message<?>> messageSender)
      Sends a ScheduledJobStartedEvent to record the execution details if enabled.
      Parameters:
      jobRef - the ScheduledJobRef for the scheduled job that the message is being sent for
      messageSender - the message sender used to send a ScheduledJobStartedEvent. This should be a Spring Cloud message producer that takes in a Message.
    • sendSuccessfulScheduledJobCompletedEventMessageIfNeeded

      public static void sendSuccessfulScheduledJobCompletedEventMessageIfNeeded(@NonNull @NonNull ScheduledJobRef jobRef, @NonNull @NonNull Consumer<org.springframework.messaging.Message<?>> messageSender)
      Sends a successful ScheduledJobCompletedEvent to record the execution details if enabled.
      Parameters:
      jobRef - the ScheduledJobRef for the scheduled job that the message is being sent for
      messageSender - the message sender used to send a ScheduledJobCompletedEvent. This should be a Spring Cloud message producer that takes in a Message.
    • sendSuccessfulScheduledJobCompletedEventMessageIfNeeded

      public static void sendSuccessfulScheduledJobCompletedEventMessageIfNeeded(@NonNull @NonNull ScheduledJobRef jobRef, @Nullable String noteMessage, @NonNull @NonNull Consumer<org.springframework.messaging.Message<?>> messageSender)
      Sends a successful ScheduledJobCompletedEvent with a note message to record the execution details if enabled.
      Parameters:
      jobRef - the ScheduledJobRef for the scheduled job that the message is being sent for
      messageSender - the message sender used to send a ScheduledJobCompletedEvent. This should be a Spring Cloud message producer that takes in a Message
    • sendScheduledJobCompletedEventMessageIfNeeded

      public static void sendScheduledJobCompletedEventMessageIfNeeded(@NonNull @NonNull ScheduledJobRef jobRef, @Nullable String noteMessage, boolean isSuccessful, @Nullable String errorMessage, @NonNull @NonNull Consumer<org.springframework.messaging.Message<?>> messageSender)
      Sends a ScheduledJobCompletedEvent to record the execution details if enabled.
      Parameters:
      jobRef - the ScheduledJobRef for the scheduled job that the message is being sent for
      noteMessage - the note message for the ScheduledJobCompletedEvent.getNote()
      isSuccessful - whether the job execution was successful
      errorMessage - the error message
      messageSender - the message sender used to send a ScheduledJobStartedEvent. This should be a Spring Cloud message producer that takes in a Message.
    • buildScheduledJobStartedEvent

      public static ScheduledJobStartedEvent buildScheduledJobStartedEvent(@NonNull @NonNull ScheduledJobRef jobRef, @NonNull @NonNull String noteMessage)
      Builds a ScheduledJobStartedEvent to record the execution details
      Parameters:
      jobRef - the jobRef from which the event is built
      noteMessage - a message to set on the execution detail
      Returns:
      ScheduledJobStartedEvent
    • buildScheduledJobCompletedEvent

      public static ScheduledJobCompletedEvent buildScheduledJobCompletedEvent(@NonNull @NonNull ScheduledJobRef jobRef, @Nullable String noteMessage, boolean isSuccessful, @Nullable String errorMessage)
      Builds a ScheduledJobCompletedEvent to record the execution details
      Parameters:
      jobRef - the jobRef from which the event is built
      noteMessage - a message to set on the execution detail
      isSuccessful - a flag indicating the scheduled job execution status
      errorMessage - error message to set on the execution detail
      Returns:
      ScheduledJobCompletedEvent