ExecutionEventListener


@ExperimentalEventsApi
interface ExecutionEventListener

Known direct subclasses
WorkMetricsInfoRepository

Repository class that calculates and stores metrics info and analytics about workers.


Listener interface that is called for events related to a worker executing.

Note that a given work request may have multiple executions due to stops and retries.

Summary

Public functions

suspend Unit
onException(throwable: Throwable, workInfo: WorkInfo)

Called when the work request fails from an exception after it has started.

suspend Unit

Called when the worker finishes and returns a value.

suspend Unit
onStarted(workInfo: WorkInfo)

Called when a work request starts executing i.e. ListenableWorker.startWork.

suspend Unit
onStopped(stopReason: Int, workInfo: WorkInfo)

Called when a work request is stopped by the system after it has started.

Public functions

onException

suspend fun onException(throwable: Throwable, workInfo: WorkInfo): Unit

Called when the work request fails from an exception after it has started.

Parameters
throwable: Throwable

Throwable thrown by worker

workInfo: WorkInfo

Snapshot of the work info

onFinished

suspend fun onFinished(result: ListenableWorker.Result, workInfo: WorkInfo): Unit

Called when the worker finishes and returns a value.

Parameters
result: ListenableWorker.Result

Result from work finishing

workInfo: WorkInfo

Snapshot of the work info

onStarted

suspend fun onStarted(workInfo: WorkInfo): Unit

Called when a work request starts executing i.e. ListenableWorker.startWork.

Parameters
workInfo: WorkInfo

Snapshot of the work info

onStopped

suspend fun onStopped(stopReason: Int, workInfo: WorkInfo): Unit

Called when a work request is stopped by the system after it has started.

Parameters
stopReason: Int

Reason why work stopped

workInfo: WorkInfo

Snapshot of the work info