use of com.netflix.titus.common.util.spectator.ContinuousSubscriptionMetrics in project titus-control-plane by Netflix.
the class InstrumentedCompletableScheduler method schedule.
public Observable<Optional<Throwable>> schedule(String completableName, Completable completable, long initialDelay, long interval, TimeUnit timeUnit) {
return Observable.create(emitter -> {
ContinuousSubscriptionMetrics subscriptionMetrics = this.completableMetricsByName.computeIfAbsent(completableName, k -> {
String rootName = metricNameRoot + ".completableScheduler." + completableName;
return SpectatorExt.continuousSubscriptionMetrics(rootName, Collections.emptyList(), registry);
});
Action0 action = () -> ObservableExt.emitError(completable.compose(subscriptionMetrics.asCompletable())).subscribe(emitter::onNext, emitter::onError);
Subscription subscription = worker.schedulePeriodically(action, initialDelay, interval, timeUnit);
emitter.setCancellation(() -> {
subscription.unsubscribe();
subscriptionMetrics.remove();
completableMetricsByName.remove(completableName);
});
}, Emitter.BackpressureMode.NONE);
}
Aggregations