JabbitListener

Watches what happens to jobs, for logging, analytics and crash reporting.

Every method has an empty body, so an implementation overrides only what it cares about. Install one — or several — through jabbit { listener(...) }.

Callbacks arrive on whichever thread the job changed on, and a listener that throws is logged and skipped rather than allowed to break the scheduler. They are meant for quick, non-blocking work: anything slower belongs in a coroutine the listener launches itself.

jabbit {
worker(SyncJob) { SyncWorker(api) }

listener(object : JabbitListener {
override fun onFailed(job: JobInfo, error: Throwable?) {
crashReporter.report("job ${job.typeName} failed: ${job.failureReason}", error)
}
})
}

On Android the scheduler is WorkManager, which also cancels work on its own — after WorkManager.cancelAllWork(), or when the application data is cleared. Those cancellations do not reach onCancelled, because they never pass through Jabbit.

Functions

Link copied to clipboard
open fun onCancelled(job: JobInfo)

The job will not run: it was cancelled, or replaced by another job of the same unique name.

Link copied to clipboard
open fun onEnqueued(job: JobInfo)

The job was accepted into the queue.

Link copied to clipboard
open fun onFailed(job: JobInfo, error: Throwable?)

The job gave up for good, either because the worker said so or because it ran out of attempts. JobInfo.failureReason says which, and error is set when the worker threw.

Link copied to clipboard
open fun onRetryScheduled(job: JobInfo, delayMillis: Long?)

The worker asked to run again.

Link copied to clipboard
open fun onStarted(job: JobInfo)

The job started running. Its constraints were satisfied and a slot was free.

Link copied to clipboard
open fun onStopped(job: JobInfo)

The platform stopped the job mid-run — constraints stopped holding, a background window expired, or the process went away. It returns to JobState.ENQUEUED and runs again later.

Link copied to clipboard
open fun onSucceeded(job: JobInfo)

The job finished successfully. A periodic job is already waiting for its next period.