Interface GridTask


public interface GridTask
In-memory representation of a Grid Task.

A Grid Task is a single unit of work in the Computational Grid framework. Tasks are stored in the database and executed asynchronously by the grid, subject to constraints such as earliest/latest possible start time, task and job dependencies, and state.

Grid Tasks are typically transactional, i.e. all database modifications either succeed or fail for the task as a whole (although this can be configured to be non-transactional).

Grid Tasks can be configured to be retried as, with a duration between attempts and a maximum number of attempts.

  • Method Summary

    Modifier and Type Method Description
    long getAttemptCount()
    Get the total number of attempts of this task so far
    long getAttemptEndTime()
    For a finished task, the end time (millis since epoch) of the last attempt
    java.lang.String getAttemptNode()
    Identifier (usually IP) of the node which attempted the task
    long getAttemptStartTime()
    Time (millis since epoch) of the current attempt
    java.lang.Long getCreatedByUserId()
    Optionally used to indicated what user created the task
    long getCreationDate()
    Creation Date for the task (millis since epoch).
    long getEarliestStartTime()
    Earliest allowable start time for the task (millis since epoch).
    java.lang.String getFailureReason()
    Get the last failure reason
    long getJobDependency()
    Id of a job which must complete before this Task can run
    long getJobId()
    Returns the surrogate id of the job of which this task is a part, if any
    long getLastAttemptMillis()
    Returns the time for last attempt
    long getLatestStartTime()
    Latest allowable start time for the task (millis since epoch).
    long getMaxAttempts()
    Get the max attempts allowed for this task.
    long getMaxRunTimeMillis()
    Returns the maximum time to allow this task to run before assuming catastrophic failure (a failure worse than throwing any throwable).
    java.lang.String getOriginNode()
    Identifier (usually IP or hostname) of the node which created the task.
    java.lang.String getParams()
    Arbitrary params to be interpreted as desired by the task type.
    java.lang.String getQueueName()
    Get the queue name for task if running under queue
    long getRetryDelayMillis()
    Returns the amount to time to wait after receiving a retry return code before retrying this task.
    long getStallTime()
    Returns millis since epoch at which the server will consider this task to have "stalled" and will automatically fail it.
    java.lang.String getState()
    Returns the current state of this task - see TaskState.
    java.lang.String getTag1()
    Tag1 may contain data specific to different task types; the meaning of this value is determined by the task type.
    java.lang.String getTag2()
    Tag2 may contain data specific to different task types; the meaning of this value is determined by the task type.
    java.lang.String getTag3()
    Tag3 may contain data specific to different task types; the meaning of this value is determined by the task type.
    java.lang.String getTag4()
    Tag4 may contain data specific to different task types; the meaning of this value is determined by the task type.
    long getTaskDependency()
    Id of a task which must complete before this Task can run
    long getTaskId()
    Returns the surrogate key of this task.
    java.lang.String getTaskInput()
    Task "input" - can be read during executing, similar to params.
    java.lang.String getTaskPerfClass()
    Returns the class name for the task performer for this task.
    java.lang.String getTaskResult()
    Returns TaskResult output string (informational purpose only)
    java.lang.String getTaskType()
    Task type (implies which TaskPerformer will be used to execute the task).
    long getTotalTimeMillis()
    Returns the total time to finish the task (this includes time for every attempt)
    boolean isPropagateFail()
    Returns whether to propagate fail.
    boolean isRunInTxn()
    Returns true if this task should be run inside of a database transaction, false otherwise.
    void setCreatedByUserId​(java.lang.Long userId)
    Optionally used to indicated what user created the task
    void setCreationDate​(long creationDate)
    Creation Date for the task (millis since epoch).
    void setEarliestStartTime​(long earliestStartTime)
    Earliest allowable start time for the task (millis since epoch).
    void setFailureReason​(java.lang.String failureReason)
    Set the failure reason on task
    void setJobDependency​(long jobDependency)
    Id of a job which must complete before this Task can run
    void setJobDependency​(GridJob job)
    Job which must complete before this Task can run
    void setJobId​(long jobId)
    Surrogate id of the job of which this task is a part, if any
    void setLatestStartTime​(long latestStartTime)
    Latest allowable start time for the task (millis since epoch).
    void setMaxAttempts​(long maxAttempts)
    The maximum number of times this task can be attempted.
    void setMaxRunTimeMillis​(long maxRunTimeMillis)
    Set the maximum time to allow this task to run before assuming catastrophic failure (a failure worse than throwing any throwable).
    void setParams​(java.lang.String params)
    Arbitrary params to be interpreted as desired by the task type.
    void setPropagateFail​(boolean propagate)
    Set propagate fail.
    void setRetryDelayMillis​(long retryDelayMillis)
    The amount to time to wait after receiving a retry return code before retrying this task.
    void setRunInTxn​(boolean runInTxn)
    Set run in transaction.
    void setTag1​(java.lang.String tag)
    Tag1 may contain data specific to different task types; the meaning of this value is determined by the task type.
    void setTag2​(java.lang.String tag)
    Tag2 may contain data specific to different task types; the meaning of this value is determined by the task type.
    void setTag3​(java.lang.String tag)
    Tag3 may contain data specific to different task types; the meaning of this value is determined by the task type.
    void setTag4​(java.lang.String tag)
    Tag4 may contain data specific to different task types; the meaning of this value is determined by the task type.
    void setTaskDependency​(GridTask otherTask)
    Task which must complete before this Task can run
    void setTaskDependency​(java.lang.Long dependsOnTaskId)
    Id of a task which must complete before this Task can run
    void setTaskInput​(java.lang.String taskInput)
    Task "input" - can be read during executing, similar to params
    void setTaskPerfClass​(java.lang.String className)
    Sets the task performer class name for the task.
    org.json.JSONObject toJSON()
    Returns all the fields from the GridTask in a JSONObject.
  • Method Details

    • getEarliestStartTime

      long getEarliestStartTime()
      Earliest allowable start time for the task (millis since epoch).
      Returns:
      Earliest allowable start time for the task (millis since epoch).
    • getLatestStartTime

      long getLatestStartTime()
      Latest allowable start time for the task (millis since epoch).
      Returns:
      Latest allowable start time for the task (millis since epoch).
    • getTaskId

      long getTaskId()
      Returns the surrogate key of this task. A new surrogate id is automatically assigned to a newly created task, so this method can be used immediately after calling GridService.newTask(String).
      Returns:
      surrogate id of the task
    • getTaskType

      java.lang.String getTaskType()
      Task type (implies which TaskPerformer will be used to execute the task).
      Returns:
      task type
    • setEarliestStartTime

      void setEarliestStartTime​(long earliestStartTime)
      Earliest allowable start time for the task (millis since epoch).
      Parameters:
      earliestStartTime - Earliest allowable start time for the task (millis since epoch).
    • setLatestStartTime

      void setLatestStartTime​(long latestStartTime)
      Latest allowable start time for the task (millis since epoch).
      Parameters:
      latestStartTime - Latest allowable start time for the task (millis since epoch).
    • getTaskInput

      java.lang.String getTaskInput()
      Task "input" - can be read during executing, similar to params.
      Returns:
      task input
    • getParams

      java.lang.String getParams()
      Arbitrary params to be interpreted as desired by the task type. Frequently contains a JSON.
    • setParams

      void setParams​(java.lang.String params)
      Arbitrary params to be interpreted as desired by the task type. Frequently contains a JSON.
    • setJobId

      void setJobId​(long jobId)
      Surrogate id of the job of which this task is a part, if any
      Parameters:
      jobId - parent job id
    • getJobId

      long getJobId()
      Returns the surrogate id of the job of which this task is a part, if any
      Returns:
      surrogate id of the job of which this task is a part, if any
    • setMaxRunTimeMillis

      void setMaxRunTimeMillis​(long maxRunTimeMillis)
      Set the maximum time to allow this task to run before assuming catastrophic failure (a failure worse than throwing any throwable).
      Parameters:
      maxRunTimeMillis -
    • getMaxRunTimeMillis

      long getMaxRunTimeMillis()
      Returns the maximum time to allow this task to run before assuming catastrophic failure (a failure worse than throwing any throwable).
      Returns:
      the maximum time to allow this task to run before assuming catastrophic failure (a failure worse than throwing any throwable).
    • setMaxAttempts

      void setMaxAttempts​(long maxAttempts)
      The maximum number of times this task can be attempted.
      Parameters:
      maxAttempts - max allowable attempts
    • getRetryDelayMillis

      long getRetryDelayMillis()
      Returns the amount to time to wait after receiving a retry return code before retrying this task.
      Returns:
      the amount to time to wait after receiving a retry return code before retrying this task.
    • setRetryDelayMillis

      void setRetryDelayMillis​(long retryDelayMillis)
      The amount to time to wait after receiving a retry return code before retrying this task.
      Parameters:
      retryDelayMillis - the amount to time to wait after receiving a retry return code before retrying this task.
    • getJobDependency

      long getJobDependency()
      Id of a job which must complete before this Task can run
      Returns:
      id of a job which must complete before this Task can run
    • getTaskDependency

      long getTaskDependency()
      Id of a task which must complete before this Task can run
      Returns:
      id of a job which must complete before this Task can run
    • setJobDependency

      void setJobDependency​(long jobDependency)
      Id of a job which must complete before this Task can run
      Parameters:
      jobDependency - id of a job which must complete before this Task can run
    • setJobDependency

      void setJobDependency​(GridJob job)
      Job which must complete before this Task can run
      Parameters:
      job - job which must complete before this Task can run
    • setTaskDependency

      void setTaskDependency​(GridTask otherTask)
      Task which must complete before this Task can run
      Parameters:
      otherTask - task which must complete before this Task can run
    • setTaskDependency

      void setTaskDependency​(java.lang.Long dependsOnTaskId)
      Id of a task which must complete before this Task can run
      Parameters:
      dependsOnTaskId - id of a task which must complete before this Task can run
    • isPropagateFail

      boolean isPropagateFail()
      Returns whether to propagate fail. If true, failure of this task to propagate to tasks and jobs that depend on this task.
      Parameters:
      propagate - whether failures are propagated
    • setPropagateFail

      void setPropagateFail​(boolean propagate)
      Set propagate fail. Set to true if you want the failure of this task to propagate to tasks and jobs that depend on this task.

      By default if you save a task propagate fail will be true and if you queue a task propagate fail will be false. If you want different behavior than these defaults then you need to set propagate fail through this method.

      Parameters:
      propagate - true if you want failures propagated
    • isRunInTxn

      boolean isRunInTxn()
      Returns true if this task should be run inside of a database transaction, false otherwise.
      Returns:
      true if this task should be run inside of a database transaction, false otherwise
    • setRunInTxn

      void setRunInTxn​(boolean runInTxn)
      Set run in transaction. Set to true if you want your task run in a transaction, false if you don't.

      By default tasks are run in transactions. This ensures that any database updates made by the task are committed in the same transaction that marks a task as succeeded. Tasks that don't update the database can benefit from running outside of a transaction.

      Running without a transaction is safest when the task is idempotent--that whether the task runs once or many times does not change the result and side effects of the task.

      Parameters:
      runInTxn - true if you want task to run in a transaction
    • getTag1

      java.lang.String getTag1()
      Tag1 may contain data specific to different task types; the meaning of this value is determined by the task type.
    • setTag1

      void setTag1​(java.lang.String tag)
      Tag1 may contain data specific to different task types; the meaning of this value is determined by the task type.
    • getTag2

      java.lang.String getTag2()
      Tag2 may contain data specific to different task types; the meaning of this value is determined by the task type.
    • setTag2

      void setTag2​(java.lang.String tag)
      Tag2 may contain data specific to different task types; the meaning of this value is determined by the task type.
    • getTag3

      java.lang.String getTag3()
      Tag3 may contain data specific to different task types; the meaning of this value is determined by the task type.
    • setTag3

      void setTag3​(java.lang.String tag)
      Tag3 may contain data specific to different task types; the meaning of this value is determined by the task type.
    • getTag4

      java.lang.String getTag4()
      Tag4 may contain data specific to different task types; the meaning of this value is determined by the task type.
    • setTag4

      void setTag4​(java.lang.String tag)
      Tag4 may contain data specific to different task types; the meaning of this value is determined by the task type.
    • setTaskInput

      void setTaskInput​(java.lang.String taskInput)
      Task "input" - can be read during executing, similar to params
      Parameters:
      taskInput - the taskInput to set
    • getState

      java.lang.String getState()
      Returns the current state of this task - see TaskState.
      Returns:
      current state of this task
    • getAttemptStartTime

      long getAttemptStartTime()
      Time (millis since epoch) of the current attempt
      Returns:
      Time (millis since epoch) of the current attempt
    • getAttemptEndTime

      long getAttemptEndTime()
      For a finished task, the end time (millis since epoch) of the last attempt
      Returns:
      for a finished task, the end time (millis since epoch) of the last attempt
    • getMaxAttempts

      long getMaxAttempts()
      Get the max attempts allowed for this task. Returns a DB default value if not set
      Returns:
      max attempts allowed for this task
    • getAttemptCount

      long getAttemptCount()
      Get the total number of attempts of this task so far
      Returns:
      total number of attempts of this task so far
    • getFailureReason

      java.lang.String getFailureReason()
      Get the last failure reason
      Returns:
      last failure reason
    • setFailureReason

      void setFailureReason​(java.lang.String failureReason)
      Set the failure reason on task
    • getQueueName

      java.lang.String getQueueName()
      Get the queue name for task if running under queue
      Returns:
      queue name for task if running under queue
    • getAttemptNode

      java.lang.String getAttemptNode()
      Identifier (usually IP) of the node which attempted the task
      Returns:
      Identifier (usually IP) of the node which attempted the task
    • getStallTime

      long getStallTime()
      Returns millis since epoch at which the server will consider this task to have "stalled" and will automatically fail it. This value is derived from the start time + the max run time.
      Returns:
      millis since epoch at which the server will consider this task to have "stalled" and will automatically fail it.
    • getCreatedByUserId

      java.lang.Long getCreatedByUserId()
      Optionally used to indicated what user created the task
      Returns:
      id of the user who created the task
    • setCreatedByUserId

      void setCreatedByUserId​(java.lang.Long userId)
      Optionally used to indicated what user created the task
      Parameters:
      userId - id of the user who created the task
    • setCreationDate

      void setCreationDate​(long creationDate)
      Creation Date for the task (millis since epoch).
      Parameters:
      creationDate - creation date for the task (millis since epoch).
    • getCreationDate

      long getCreationDate()
      Creation Date for the task (millis since epoch).
      Returns:
      Creation date for the task (millis since epoch).
    • toJSON

      org.json.JSONObject toJSON()

      Returns all the fields from the GridTask in a JSONObject. For example:

       {
         "ATTEMPT_NODE":"MYMACHINE.ONENETWORK.COM",
         "ATTEMPT_START_TIME":"2010-07-14 23:29:44.433",
         "EARLIEST_START_TIME":"2010-07-14 23:29:42.412",
         "LAST_ATTEMPT_MILLIS":0,
         "MAX_ATTEMPTS":6,"ATTEMPT_COUNT":1,
         "MAX_RUN_TIME_MILLIS":600000
         "RETRY_DELAY_MILLIS":10000,
         "STALL_TIME":"2010-07-14 23:39:44.433",
         "STATE":"RUNNING",
         "SYS_TASK_ID":10356,
         "TASK_TYPE":"PollAndEnqueueFiles",
         "TOTAL_TIME_MILLIS":0,
       }
       
      Returns:
      JSON representation of this GridTask
    • getOriginNode

      java.lang.String getOriginNode()
      Identifier (usually IP or hostname) of the node which created the task.
      Returns:
      identifier of this node which created the task
    • getTaskResult

      java.lang.String getTaskResult()
      Returns TaskResult output string (informational purpose only)
      Returns:
      TaskResult output string
    • getTotalTimeMillis

      long getTotalTimeMillis()
      Returns the total time to finish the task (this includes time for every attempt)
      Returns:
      the total time to finish the task
    • getLastAttemptMillis

      long getLastAttemptMillis()
      Returns the time for last attempt
      Returns:
      time for last attempt
    • getTaskPerfClass

      java.lang.String getTaskPerfClass()
      Returns the class name for the task performer for this task. May be null if the task has not run or if the TaskPerformerConfig is not present.
      Returns:
      class name for the task performer
    • setTaskPerfClass

      void setTaskPerfClass​(java.lang.String className)
      Sets the task performer class name for the task. This is used when processing fail-pending tasks to call TaskPerformer.addToFailTransaction(String, String, String) and is documentational otherwise.
      Parameters:
      className -