WorkRequest

@Serializable
sealed interface WorkRequest

A request to schedule background work, identified by a stable task id.

Sealed: v1 supports OneTime and Periodic. Both share an ephemeral flag for the cold-launch sweep — see BackgroundTaskManager.attachTo / BackgroundTaskManager.registerHandlers.

Inheritors

Types

Link copied to clipboard
object Companion
Link copied to clipboard
@Serializable
data class OneTime(val taskId: String, val constraints: WorkConstraints = WorkConstraints(), val input: WorkInput = WorkInput.empty(), val ephemeral: Boolean = false, val initialDelay: Duration = Duration.ZERO, val backoff: BackoffPolicy = BackoffPolicy.exponential(30.seconds), val executionHint: ExecutionHint = ExecutionHint.Standard) : WorkRequest

Run once; survives process death and reboot unless ephemeral.

Link copied to clipboard
@Serializable
data class Periodic(val taskId: String, val constraints: WorkConstraints = WorkConstraints(), val input: WorkInput = WorkInput.empty(), val ephemeral: Boolean = false, val interval: Duration, val flexWindow: Duration? = null) : WorkRequest

Repeats indefinitely until cancelled. Android floor is 15 minutes (validated by the scheduler at enqueue time); iOS / macOS have no system floor but we recommend ≥ 15 minutes for parity.

Properties

Link copied to clipboard
Link copied to clipboard
abstract val ephemeral: Boolean

If true, this request is cleared at app cold-start before any worker dispatches. Schedule it again from app code at a known-safe init point.

Link copied to clipboard
abstract val input: WorkInput
Link copied to clipboard
abstract val taskId: String