TaskExecutionContext

data class TaskExecutionContext(val taskId: String, val retryCount: Int = 0, val payload: String? = null, val tags: Set<String> = emptySet())

Context provided to a task handler at execution time.

Available as the receiver inside handlers registered with context support:

kmpWorker.register("upload") { ctx ->
val data = ctx.payload?.let { Json.decodeFromString<MyData>(it) }
println("Attempt ${ctx.retryCount + 1} for ${ctx.taskId}")
uploadService.upload(data)
}

Parameters

taskId

The unique ID of the task currently executing.

retryCount

Zero-based number of times this task has been retried.

payload

Optional serialized data from TaskRequest.payload.

tags

Tags attached to the original TaskRequest, if any.

Constructors

Link copied to clipboard
constructor(taskId: String, retryCount: Int = 0, payload: String? = null, tags: Set<String> = emptySet())

Properties

Link copied to clipboard

Returns true if this is the first execution attempt (not a retry).

Link copied to clipboard

Returns true if this is a retry attempt.

Link copied to clipboard
val payload: String? = null
Link copied to clipboard
val retryCount: Int = 0
Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard

Decodes the payload of this TaskExecutionContext into a strongly-typed object.

Link copied to clipboard
suspend fun reportProgress(progress: Float, message: String? = null)

Reports progress from within a task handler.