Package org.jobrunr.jobs.context
Class JobContext
- java.lang.Object
-
- org.jobrunr.jobs.context.JobContext
-
- Direct Known Subclasses:
RunnerJobContext
public class JobContext extends java.lang.Object
The JobContext class gives access to the Job id, the Job name, the state, ... .It also allows to store some data between different job retries.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
JobContext.Metadata
-
Field Summary
Fields Modifier and Type Field Description static JobContext
Null
-
Constructor Summary
Constructors Modifier Constructor Description protected
JobContext()
protected
JobContext(Job job)
Keep constructor package protected to remove confusion on how to instantiate the JobContext.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.time.Instant
getCreatedAt()
java.util.UUID
getJobId()
java.lang.String
getJobName()
StateName
getJobState()
java.util.Map<java.lang.String,java.lang.Object>
getMetadata()
Gives access to Job Metadata via an UnmodifiableMap.java.lang.String
getSignature()
java.time.Instant
getUpdatedAt()
JobDashboardLogger
logger()
JobDashboardProgressBar
progressBar(int totalAmount)
JobDashboardProgressBar
progressBar(long totalAmount)
void
saveMetadata(java.lang.String key, java.lang.Object metadata)
Allows saving metadata for a certain Job.void
saveMetadataIfAbsent(java.lang.String key, java.lang.Object metadata)
Allows saving metadata for a certain Job.
-
-
-
Field Detail
-
Null
public static final JobContext Null
-
-
Constructor Detail
-
JobContext
protected JobContext()
-
JobContext
protected JobContext(Job job)
Keep constructor package protected to remove confusion on how to instantiate the JobContext. Tip - To use the JobContext in your Job, pass JobContext.Null- Parameters:
job
- the job for this JobContext
-
-
Method Detail
-
getJobId
public java.util.UUID getJobId()
-
getJobName
public java.lang.String getJobName()
-
getJobState
public StateName getJobState()
-
getCreatedAt
public java.time.Instant getCreatedAt()
-
getUpdatedAt
public java.time.Instant getUpdatedAt()
-
getSignature
public java.lang.String getSignature()
-
logger
public JobDashboardLogger logger()
-
progressBar
public JobDashboardProgressBar progressBar(int totalAmount)
-
progressBar
public JobDashboardProgressBar progressBar(long totalAmount)
-
getMetadata
public java.util.Map<java.lang.String,java.lang.Object> getMetadata()
Gives access to Job Metadata via an UnmodifiableMap. To save Metadata, use thesaveMetadata(String, Object)
method- Returns:
- all user defined metadata about a Job.
-
saveMetadata
public void saveMetadata(java.lang.String key, java.lang.Object metadata)
Allows saving metadata for a certain Job. The value must either be a simple type (String, UUID, Integers, ...) or implement the Metadata interface for serialization to Json. Note that it is important that the objects you save are thread-safe (e.g. a CopyOnWriteArrayList, ... ).If the key already exists, the metadata is updated.
- Parameters:
key
- the key to store the metadatametadata
- the metadata itself
-
saveMetadataIfAbsent
public void saveMetadataIfAbsent(java.lang.String key, java.lang.Object metadata)
Allows saving metadata for a certain Job. The value must either be a simple type (String, UUID, Integers, ...) or implement the Metadata interface for serialization to Json. Note that it is important that the objects you save are thread-safe (e.g. a CopyOnWriteArrayList, ... ).If the key already exists, the metadata is NOT updated.
- Parameters:
key
- the key to store the metadatametadata
- the metadata itself
-
-