WorkDebugTab

The WorkManager tab: the app's work, the events of each run, and cancel and prune, under /api/v1/work/. It needs WorkManager 2.12.0 or newer in the app.

Register it from debug code, and pass the app's WorkManager configuration through configure, so that the tab gets WorkManager's events:

// src/main
class App : Application(), Configuration.Provider {
override val workManagerConfiguration: Configuration
get() = LustroBootstrap.workManagerConfiguration(Configuration.Builder()).build()
}

// src/debug, LustroBootstrap
val work = WorkDebugTab.create(app, uniqueNames = listOf("sync"))
fun workManagerConfiguration(builder: Configuration.Builder) = work.configure(builder)
Lustro.builder(app).addTab(work).build().start()

The listeners go into the app's own Configuration, so the app initializes WorkManager on demand: it implements Configuration.Provider or calls WorkManager.initialize, and removes WorkManagerInitializer from the manifest. Without that, the tab shows the work without events.

The tab reads the work through WorkManager's public API: its state, tags, attempts, output, progress, constraints, and schedule. WorkInfo has no unique name and no prerequisites, so the tab reads the name of each work, and the work that it waits for in a chain, from WorkManager's own database, through WorkManager's connection, and falls back to the names that the app lists in uniqueNames when the app's WorkManager does not have the calls. It asks for the WorkManager instance only after the app has initialized it, so it never changes when WorkManager starts.

The tab records the events of each run (enqueued, unblocked, updated, cancelled, prerequisite failed, started, stopped, finished, and exception), with the result, its output, the stop reason, and the exception's stack trace, from Lustro.start() to Lustro.stop(), also while the app is in the background, and keeps them on the heap, in a buffer of bufferBytes. They end with the process: the events of a process that the system started in the background and stopped before a client asked are lost. Its listeners forward to the app's whether the tab records or not. With a WorkMetricsInfoRepository of work-analytics, which keeps the times and attempts of each run on disk, the tab also shows that history.

POST cancel cancels work by its id, unique name, or tag, and POST prune deletes finished work, as WorkManager.pruneWork() does. Every client that has the token can do both.

In the console, the tab lists the work with its state, filtered by state, tag, worker class, and unique name, and shows the selected work's details, the timeline of its events, and its work-analytics history, with Cancel and Prune. GET /api/v1/work/_schema describes its routes.

Types

Link copied to clipboard
object Companion

Factory for WorkDebugTab.

Properties

Link copied to clipboard
open override val icon: String
Link copied to clipboard
open override val id: String
Link copied to clipboard
open override val order: Int = 50
Link copied to clipboard
Link copied to clipboard
open override val title: String

Functions

Link copied to clipboard

Sets the tab's event listeners on builder and returns it, for the app to call build() on. Call it last, after the app sets its own listeners: each of the tab's listeners records the event and then calls the app's listener with it, and what the app's listener throws reaches WorkManager as before. A work-analytics repository that the app set as its listeners keeps working.

Link copied to clipboard
open fun handle(request: DebugRequest): DebugResponse?
Link copied to clipboard
open override fun onStart()

Starts recording the events of the listeners that configure set.

Link copied to clipboard
open override fun onStop()

Stops recording. The buffer keeps its events, and the listeners keep forwarding to the app's.

Link copied to clipboard
open override fun renderContent(): String

The view's static shell; work.js and work.css in the assets fill and style it.

Link copied to clipboard
open fun renderScript(): String
Link copied to clipboard
open fun renderStyles(): String
Link copied to clipboard
open fun schema(): String?