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 Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void checkIn​(java.io.Serializable message)
      Checkin allows you to display a message for long running tasks, so that you can see the progress.
      void delete​(JobStatus status, java.io.Serializable why)
      Delete this job
      Context getContext()
      Return job context
      java.lang.Throwable getException()
      Any error detail, if it fails during execution
      long getExecutionTime()
      Total execution time of the fetched RqueueMessages
      int getFailureCount()
      Number of times this job has failed
      java.lang.String getId()
      Get job id corresponding to a message
      Execution getLatestExecution()
      Return latest execution data
      java.lang.Object getMessage()
      A message that was enqueued
      java.lang.String getMessageId()
      Get message id corresponding to this job
      MessageMetadata getMessageMetadata()
      MessageMetadata corresponding the enqueued message
      QueueDetail getQueueDetail()
      Queue detail on which this job was executing
      RqueueMessage getRqueueMessage()
      RqueueMessage that's consumed by this job
      JobStatus getStatus()
      The current status of this job, the message can have different status.
      java.time.Duration getVisibilityTimeout()
      Get current visibility timeout of this job, if visibility timeout has already elapsed than return zero value
      boolean hasMovedToDeadLetterQueue()
      Reports true when this job is moved to dead letter queue
      boolean isDeleted()
      Return whether this job was deleted, this returns true in two cases
      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.
      boolean isReleased()
      Whether this job is released back to the queue or not in two cases
      void release​(JobStatus status, java.io.Serializable why)
      Release this job back to queue, this job available for execution after one second.
      void release​(JobStatus status, java.io.Serializable why, java.time.Duration duration)
      Release this job back to the queue, the released job would be available for re-execution after the duration time.
      void setContext​(Context context)
      Set job context
      boolean updateVisibilityTimeout​(java.time.Duration deltaDuration)
      Update the visibility timeout of this job, the delta duration would be added in the current visibility timeout.
    • Method Detail

      • getId

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

        java.lang.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
      • checkIn

        void checkIn​(java.io.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

        java.time.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​(java.time.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

        java.lang.Object getMessage()
        A message that was enqueued
        Returns:
        an object could be null if deserialization fail.
      • 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:
        MessageMetadata
      • getException

        java.lang.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,
                     java.io.Serializable why,
                     java.time.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,
                     java.io.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,
                    java.io.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
      • 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