Package com.github.sonus21.rqueue.core
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
Modifier and TypeMethodDescriptionvoidcheckIn(Serializable message) Checkin allows you to display a message for long running tasks, so that you can see the progress.voiddelete(JobStatus status, Serializable why) Delete this jobReturn job contextAny error detail, if it fails during executionlongTotal execution time of the fetched RqueueMessagesintNumber of times this job has failedgetId()Get job id corresponding to a messageReturn latest execution dataA message that was enqueuedGet message id corresponding to this jobMessageMetadata corresponding the enqueued messageQueue detail on which this job was executingGet raw message that was enqueued, it's serialized string of the enqueued objectRqueueMessage that's consumed by this jobThe current status of this job, the message can have different status.Get current visibility timeout of this job, if visibility timeout has already elapsed than return zero valuebooleanReports true when this job is moved to dead letter queuebooleanReturn whether this job was deleted, this returns true in two casesbooleanWhether this job is discarded or not, a message is discarded when it's all retries are over and no dead letter queue is configured.booleanWhether this job is released back to the queue or not in two casesvoidrelease(JobStatus status, Serializable why) Release this job back to queue, this job available for execution after one second.voidrelease(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.voidsetContext(Context context) Set job contextvoidsetMessage(Object message) There are times when message can not be deserialized from the string to Object, this can happen when class information is missing.booleanupdateVisibilityTimeout(Duration deltaDuration) Update the visibility timeout of this job, the delta duration would be added in the current visibility timeout.
-
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
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
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
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
Set job context- Parameters:
context- context object
-
release
Release this job back to the queue, the released job would be available for re-execution after the duration time.- Parameters:
status- job statuswhy- why do want to release this jobduration- any positive duration
-
release
Release this job back to queue, this job available for execution after one second.- Parameters:
status- what should be the job statuswhy- why do you want to delete this job
-
delete
Delete this job- Parameters:
status- what should be the job statuswhy- why do you want to delete this job
-
isDeleted
boolean isDeleted()Return whether this job was deleted, this returns true in two cases1. when message is deleted using
delete(JobStatus, Serializable)method2. 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 casesWhen message was released using
release(JobStatus, Serializable)orrelease(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
-