Interface Job

All Known Implementing Classes:
JobImpl

public interface Job
On each execution Rqueue creates a job to track it's status and execution progress.

A job belongs to a single message poll, each message listener call creates an execution Execution and that has a detail for specific execution. Overall job status can be found using this job interface. This object is available via Header in listener method.

  • Method Details

    • getId

      String getId()
      Get job id corresponding to a message
      Returns:
      string job id
    • getMessageId

      String getMessageId()
      Get message id corresponding to this job
      Returns:
      message id
    • getRqueueMessage

      RqueueMessage getRqueueMessage()
      RqueueMessage that's consumed by this job
      Returns:
      an object of RqueueMessage
    • getRawMessage

      String getRawMessage()
      Get raw message that was enqueued, it's serialized string of the enqueued object
      Returns:
      string never null
    • checkIn

      void checkIn(Serializable message)
      Checkin allows you to display a message for long running tasks, so that you can see the progress.

      The checking message could be anything given message's JSON serializable/deserializable. The message could be the current status of the job or anything else.

      NOTE: Checkin is not allowed for periodic job

      Parameters:
      message - a serializable message
    • getVisibilityTimeout

      Duration getVisibilityTimeout()
      Get current visibility timeout of this job, if visibility timeout has already elapsed than return zero value
      Returns:
      remaining duration that this job can take, otherwise other listener will consume this message
    • updateVisibilityTimeout

      boolean updateVisibilityTimeout(Duration deltaDuration)
      Update the visibility timeout of this job, the delta duration would be added in the current visibility timeout. For example to add 10 seconds call this with Duration.ofSeconds(10), to subtract 10 seconds call this with Duration.ofSeconds(-10). This method returns when message exist in the processing queue, if message is already processed then it would return false.
      Parameters:
      deltaDuration - the delta time that needs to added to the existing visibility timeout
      Returns:
      true/false whether this operation was success or not
    • getMessage

      Object getMessage()
      A message that was enqueued
      Returns:
      an object could be null if deserialization fail.
    • setMessage

      void setMessage(Object message)
      There are times when message can not be deserialized from the string to Object, this can happen when class information is missing. In such cases only raw message is available but application can add a middleware to deserialize such messages and set in this so that other middleware(s) can use the correct message object. Some use cases could be
      • Message was serialized to JSON without class information
      • Message was serialized to XML without class information
      • Message was serialized to Protobuf
      • Message was serialized to MessagePack
      Parameters:
      message - message object
    • getMessageMetadata

      MessageMetadata getMessageMetadata()
      MessageMetadata corresponding the enqueued message
      Returns:
      message metadata object
    • getStatus

      JobStatus getStatus()
      The current status of this job, the message can have different status.
      Returns:
      job status
      See Also:
    • getException

      Throwable getException()
      Any error detail, if it fails during execution
      Returns:
      an error object
    • getExecutionTime

      long getExecutionTime()
      Total execution time of the fetched RqueueMessages
      Returns:
      total execution time, that's sum of all listener method calls.
    • getQueueDetail

      QueueDetail getQueueDetail()
      Queue detail on which this job was executing
      Returns:
      queue detail object
    • getLatestExecution

      Execution getLatestExecution()
      Return latest execution data
      Returns:
      an execution object
    • getContext

      Context getContext()
      Return job context
      Returns:
      job context
    • setContext

      void setContext(Context context)
      Set job context
      Parameters:
      context - context object
    • release

      void release(JobStatus status, Serializable why, Duration duration)
      Release this job back to the queue, the released job would be available for re-execution after the duration time.
      Parameters:
      status - job status
      why - why do want to release this job
      duration - any positive duration
    • release

      void release(JobStatus status, Serializable why)
      Release this job back to queue, this job available for execution after one second.
      Parameters:
      status - what should be the job status
      why - why do you want to delete this job
    • delete

      void delete(JobStatus status, Serializable why)
      Delete this job
      Parameters:
      status - what should be the job status
      why - why do you want to delete this job
    • isDeleted

      boolean isDeleted()
      Return whether this job was deleted, this returns true in two cases

      1. when message is deleted using delete(JobStatus, Serializable) method

      2. Job's status is terminal status.

      Returns:
      true/false
    • isReleased

      boolean isReleased()
      Whether this job is released back to the queue or not in two cases

      When message was released using release(JobStatus, Serializable) or release(JobStatus, Serializable, Duration)

      job is failed, so it will be retried later

      Returns:
      true/false
    • hasMovedToDeadLetterQueue

      boolean hasMovedToDeadLetterQueue()
      Reports true when this job is moved to dead letter queue
      Returns:
      true/false
    • isDiscarded

      boolean isDiscarded()
      Whether this job is discarded or not, a message is discarded when it's all retries are over and no dead letter queue is configured.
      Returns:
      true/false
    • getFailureCount

      int getFailureCount()
      Number of times this job has failed
      Returns:
      failure count