1. Introduction
Micronaut snitch helps you keep track of running asynchronous jobs (Quartz, Scheduled).
2. Installation
repositories { mavenCentral() } dependencies { compile 'com.agorapulse:micronaut-snitch:{project-version}' }
There are variants for older Micronaut versions as well. You can use micronaut-1.0 or micronaut-2.0 suffix for
different versions of Micronaut.
|
3. Configuration
By default, events are sent to Dead Man’s Snitch (https://deadmanssnitch.com/).
You can configure an alternative URL by setting snitch.url
.
You must configure at least one id for reporting:
snitches: id: mydmsid
You can also specify ids for multiple jobs:
snitches: jobs: cafebabe: id: javababy babecafe: id: babycino
4. Usage
The simplest use case is to annotate the method executed by the job with @Snitch
:
@Snitch void doSomething() { // do something }
If you have multiple configurations, you can specify the one to use:
@Snitch("babecafe") void doSomething() { // do something }
By default, the provider is notified after method execution, but you can change this using the before
annotation property.
Then the report will only send successful messages, even if an error occurs during execution.
@Snitch(before = true) void doSomething() { // do something reported at the beginning }
You may also inject SnitchService
into your service. For multiple configurations environment,
use the @Named
annotation to retrieve a particular instance:
@Singleton class MyService { @Named("babecafe") private final SnitchService snitchService; public MyService(SnitchService snitchService) { this.snitchService = snitchService; } void doSomething() { // do something snitchService.snitch(); } }