Class WorkerContext


  • public class WorkerContext
    extends java.lang.Object
    This 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.ScheduledTask 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
      int getAttemptNumber()
      Returns the attemptNumber of the NodeRun that's being executed.
      java.lang.String getIdempotencyKey()
      Returns an idempotency key that can be used to make calls to upstream api's idempotent across TaskRun Retries.
      java.lang.String getLogOutput()
      Returns the current logOutput.
      io.littlehorse.sdk.common.proto.NodeRunId getNodeRunId()
      Returns the NodeRun ID for the Task that was just scheduled.
      java.util.Date getScheduledTime()
      Returns the time at which the task was scheduled by the processor.
      io.littlehorse.sdk.common.proto.TaskRunId getTaskRunId()
      Returns the TaskRunId of this TaskRun.
      java.lang.String getUserGroup()
      If this TaskRun is a User Task Reminder TaskRun, then this method returns the UserGroup that the associated UserTask is assigned to.
      java.lang.String getUserId()
      If this TaskRun is a User Task Reminder TaskRun, then this method returns the UserId of the user who the associated UserTask is assigned to.
      io.littlehorse.sdk.common.proto.WfRunId getWfRunId()
      Returns the Id of the WfRun for the NodeRun that's being executed.
      void log​(java.lang.Object thing)
      Provides a way to push data into the log output.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • WorkerContext

        public WorkerContext​(io.littlehorse.sdk.common.proto.ScheduledTask 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 io.littlehorse.sdk.common.proto.WfRunId 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.NodeRunId 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.TaskRunId getTaskRunId()
        Returns the TaskRunId of this TaskRun.
        Returns:
        the associated TaskRunId.
      • getUserId

        public java.lang.String getUserId()
        If this TaskRun is a User Task Reminder TaskRun, then this method returns the UserId of the user who the associated UserTask is assigned to. Returns null if: - this TaskRun is not a Reminder Task - this TaskRun is a Reminder Task, but the UserTaskRun does not have an assigned user id.
        Returns:
        the id of the user that the associated UserTask is assigned to.
      • getUserGroup

        public java.lang.String getUserGroup()
        If this TaskRun is a User Task Reminder TaskRun, then this method returns the UserGroup that the associated UserTask is assigned to. Returns null if: - this TaskRun is not a Reminder Task - this TaskRun is a Reminder Task, but the UserTaskRun does not have an associated User Group
        Returns:
        the id of the User Group that the associated UserTask is assigned to.
      • 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.