Search in sources :

Example 1 with ContinuousSubscriptionMetrics

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);
}
Also used : Action0(rx.functions.Action0) ContinuousSubscriptionMetrics(com.netflix.titus.common.util.spectator.ContinuousSubscriptionMetrics) Subscription(rx.Subscription)

Aggregations

ContinuousSubscriptionMetrics (com.netflix.titus.common.util.spectator.ContinuousSubscriptionMetrics)1 Subscription (rx.Subscription)1 Action0 (rx.functions.Action0)1