Package io.littlehorse.sdk.worker
Class WorkerContext
- java.lang.Object
-
- io.littlehorse.sdk.worker.WorkerContext
-
public class WorkerContext extends java.lang.ObjectThis class contains runtime information about the specific WfRun and NodeRun that is being executed by the Task Worker. It may optionally be added into the input parameters of your LHTaskMethod, and the Runtime will provision the WorkerContext and pass it into the method.
-
-
Constructor Summary
Constructors Constructor Description WorkerContext(io.littlehorse.sdk.common.proto.ScheduledTaskPb scheduledTask, java.util.Date scheduleTime)Constructor for internal use by the Task Worker Library.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetAttemptNumber()Returns the attemptNumber of the NodeRun that's being executed.java.lang.StringgetIdempotencyKey()Returns an idempotency key that can be used to make calls to upstream api's idempotent across TaskRun Retries.java.lang.StringgetLogOutput()Returns the current logOutput.io.littlehorse.sdk.common.proto.NodeRunIdPbgetNodeRunId()Returns the NodeRun ID for the Task that was just scheduled.java.util.DategetScheduledTime()Returns the time at which the task was scheduled by the processor.io.littlehorse.sdk.common.proto.TaskRunIdPbgetTaskRunId()java.lang.StringgetWfRunId()Returns the Id of the WfRun for the NodeRun that's being executed.voidlog(java.lang.Object thing)Provides a way to push data into the log output.
-
-
-
Constructor Detail
-
WorkerContext
public WorkerContext(io.littlehorse.sdk.common.proto.ScheduledTaskPb scheduledTask, java.util.Date scheduleTime)Constructor for internal use by the Task Worker Library.- Parameters:
scheduledTask- is the raw payload for the scheduled task.scheduleTime- is the time that the task was actually scheduled.
-
-
Method Detail
-
getWfRunId
public java.lang.String getWfRunId()
Returns the Id of the WfRun for the NodeRun that's being executed.- Returns:
- the Id of the WfRun for the NodeRun that's being executed.
-
getNodeRunId
public io.littlehorse.sdk.common.proto.NodeRunIdPb getNodeRunId()
Returns the NodeRun ID for the Task that was just scheduled.- Returns:
- a `NodeRunIdPb` protobuf class with the ID from the executed NodeRun.
-
getAttemptNumber
public int getAttemptNumber()
Returns the attemptNumber of the NodeRun that's being executed. If this is the first attempt, returns zero. If this is the first retry, returns 1, and so on.- Returns:
- the attempt number of the NodeRun that's being executed.
-
getScheduledTime
public java.util.Date getScheduledTime()
Returns the time at which the task was scheduled by the processor. May be useful in certain customer edge cases, eg. to determine whether it's too late to actually perform an action, when (now() - getScheduledTime()) is above some threshold, etc.- Returns:
- the time at which the current NodeRun was scheduled.
-
log
public void log(java.lang.Object thing)
Provides a way to push data into the log output. Any object may be passed in; its String representation will be appended to the logOutput of this NodeRun.- Parameters:
thing- the Object to log to the NodeRun's logOutput.
-
getLogOutput
public java.lang.String getLogOutput()
Returns the current logOutput.- Returns:
- the current log output.
-
getTaskRunId
public io.littlehorse.sdk.common.proto.TaskRunIdPb getTaskRunId()
-
getIdempotencyKey
public java.lang.String getIdempotencyKey()
Returns an idempotency key that can be used to make calls to upstream api's idempotent across TaskRun Retries.- Returns:
- an idempotency key.
-
-