Interface AutomationQueue

All Known Implementing Classes:
AutomationQueueImpl

public interface AutomationQueue
Provides a tenant aware queue that is used to execute automation rules ordered by priority and insertion order with limits overall and per tenant that can be claimed for execution.
  • Method Details

    • addItem

      long addItem(Environment env, QueueItemBean item)
      Adds a single item to the queue.
      Parameters:
      env - The env we are in (prod or dev).
      item - The queue item to add to the queue.
      Returns:
      the id of the item inserted
    • addItems

      void addItems(Environment environment, List<QueueItemBean> items)
      Adds multiple queue items in bulk to the queue. Listeners will only be notified when all items have been added.
      Parameters:
      environment - The env we are in (prod or dev).
      items - The queue item to add to the queue.
    • claimItems

      List<QueueItemBean> claimItems(Environment env, String claimant, ClaimLimits limits)
      Claims multiple items for execution from the queue up the the limits specified. May return an empty list if the queue is empty or limits have been reached.
      Parameters:
      env - The env we are in (prod or dev).
      claimant - The name of the claimant executing the rules
      limits - queue limits that specify how many items can be claimed.
      Returns:
      list of items to execute
    • claimItemsById

      List<Long> claimItemsById(Environment env, String claimant, ClaimLimits limits)
      Same as claimItems(Environment, String, ClaimLimits) but will only retrieve and return ids which is faster when clamining many items.
    • claimItem

      Optional<QueueItemBean> claimItem(Environment env, String claimant, ClaimLimits limits)
      Claims a single item for execution from the queue up the the limits specified. May return empty if the queue is empty or limits have been reached.
      Parameters:
      env - The env we are in (prod or dev).
      claimant - The name of the claimant executing the rules
      limits - queue limits that specify how many items can be claimed.
      Returns:
      item to execute
    • resolveItem

      long resolveItem(TenantExecution tenantExecution, long itemId)
      Resolves a previously claimed item.
      Parameters:
      tenantExecution - the execution of this rule.
      itemId - The id of the item to resolve.
      Returns:
      remaining items queued.
    • clearUnresolved

      void clearUnresolved(Environment env, Date olderThan)
      Removes any items from the queue that were claimed older than a certain date. This can be used to remove stuck items from the queue.
      Parameters:
      env - The env we are in (prod or dev).
      olderThan - Any items older than this date will be removed (based on claim time)
    • getStatistics

      QueueStatistics getStatistics(Environment env)
      Return current queue stats
      Parameters:
      env - The env we are in (prod or dev).
      Returns:
      current queue stats
    • getItem

      Optional<QueueItemBean> getItem(Environment env, long itemId)
      Retrieve an item by its id. May be empty.
      Parameters:
      env - The env we are in (prod or dev).
      itemId - The id of the item to retrieve
      Returns:
      the item or empty
    • getItemAndMarkForProcessing

      Optional<QueueItemBean> getItemAndMarkForProcessing(Environment env, long itemId)
      This will mark the item for processing and only return it if it wasn't already processing.
      Parameters:
      env - The env we are in (prod or dev).
      itemId - The id of the item to retrieve
      Returns:
      the item or empty
    • hasMoreItemsQueued

      boolean hasMoreItemsQueued(Environment env, long auditItemId)
      Check if a particular audit item has more items queue up for execution. This can be used to check if a rule execution has finished.
      Parameters:
      env - The env we are in (prod or dev).
      auditItemId - The id of the audit item
      Returns:
      true if there's more unclaimed items in the queue for an audit item
    • isRuleInProgress

      boolean isRuleInProgress(TenantContext context, long ruleId)
      Checks if this rule is already executing with an audit item id other than the current one
      Parameters:
      context - The tenant to execute this for
      ruleId - The id of the rule
      Returns:
      true if the rule is in progress already
    • getCount

      long getCount(Environment env)
    • getEarliestUnprocessedItemCreatedTime

      long getEarliestUnprocessedItemCreatedTime()
      Retrieves the earliest created time of an unprocessed item in the queue.
      Returns:
      the earliest created time of an unprocessed item, or -1 if no unprocessed items are present.
    • getAutomationQueueInsightByEventType

      AutomationQueueInsight getAutomationQueueInsightByEventType(int limit)
      Gets the automation queue insight with events grouped by event type.
      Parameters:
      limit - the number of groups to return
      Returns:
      the automation queue insight
    • getAutomationQueueInsightByRule

      AutomationQueueInsight getAutomationQueueInsightByRule(int limit)
      Gets the automation queue insight with events grouped by rule.
      Parameters:
      limit - the number of groups to return
      Returns:
      the automation queue insight