createTask()

Overview

public string function createTask(
      required string   event               
    ,          struct   args                
    ,          string   adminOwner           = ""
    ,          string   webOwner             = ""
    ,          boolean  runNow               = false
    ,          timespan runIn               
    ,          boolean  discardOnComplete    = false
    ,          any      discardAfterInterval
    ,          any      retryInterval       
    ,          string   title                = ""
    ,          array    titleData           
    ,          string   resultUrl            = ""
    ,          string   returnUrl            = ""
    ,          string   reference            = ""
)

Registers a new task, optionally running it there and then in a background thread

Arguments

NameTypeRequiredDescription
eventstringYesColdbox event that will be run
argsstructNoArgs struct to pass to the coldbox event
adminOwnerstringNo (default="")Optional admin user ID, owner of the task
webOwnerstringNo (default="")Optional website user ID, owner of the task
runNowbooleanNo (default=false)Whether or not to immediately run the task in a background thread. **Note:** If neither `runNow` or `runIn` is set, you will be responsible for running the task yourself with runTask().
runIntimespanNoOptional *timespan* (`CreateTimeSpan()`) to delay the execution of this task (will only be used if `runNow` is `false`). **Note:** If neither `runNow` or `runIn` is set, you will be responsible for running the task yourself with runTask().
discardOnCompletebooleanNo (default=false)Whether or not to discard the task once completed or permanently failed. Defaults to `false`
discardAfterIntervalanyNoInterval from completion after which the task will be deleted. Defaults to 1 day. Only used when `discardOnComplete` is set to `false` (default).
retryIntervalanyNoDefinition of retry attempts for tasks that fail to run. Either a single struct, or array of structs with the following keys: `tries`: number of attempts, `interval`:number in seconds between tries (can also use CreateTimeSpan()). For example: `[ { tries:3, interval=CreateTimeSpan( 0, 0, 5, 0 ) }, { tries:2, interval=3600 }]` will retry three times with 5 minutes between attempts and then retry a further two times with 60 minutes between attempts.
titlestringNo (default="")Optional title of the task, can be an i18n resource URI for later translation. This will be used in any task progress UIs, etc.
titleDataarrayNoOptional array of strings that will be passed into translateResource() along with title URI to create translatable title
resultUrlstringNo (default="")Optional URL at which the result of this task can be viewed / downloaded. The token, `{taskId}`, within the URL will be replaced with the actual ID of the task
returnUrlstringNo (default="")Optional URL to which to direct users from core admin UIs when they have finished with viewing a task
referencestringNo (default="")Optional string with which to provide a key reference for your task