io.github.sinri.keel.servant.queue.KeelQueueTask Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Keel Show documentation
Show all versions of Keel Show documentation
A website framework with VERT.X for ex-PHP-ers, exactly Ark Framework Users.
The newest version!
package io.github.sinri.keel.servant.queue;
import io.github.sinri.keel.verticles.KeelVerticleImplWithIssueRecorder;
import io.vertx.core.Future;
import javax.annotation.Nonnull;
/**
* @since 2.1
*/
public abstract class KeelQueueTask extends KeelVerticleImplWithIssueRecorder {
QueueWorkerPoolManager queueWorkerPoolManager;
final void setQueueWorkerPoolManager(QueueWorkerPoolManager queueWorkerPoolManager) {
this.queueWorkerPoolManager = queueWorkerPoolManager;
}
@Nonnull
abstract public String getTaskReference();
@Nonnull
abstract public String getTaskCategory();
@Override
protected final void startAsKeelVerticle() {
this.queueWorkerPoolManager.whenOneWorkerStarts();
Future.succeededFuture()
.compose(v -> {
notifyAfterDeployed();
return Future.succeededFuture();
})
.compose(v -> run())
.recover(throwable -> {
getIssueRecorder().exception(throwable, r -> r.message("KeelQueueTask Caught throwable from Method run"));
return Future.succeededFuture();
})
.eventually(() -> {
getIssueRecorder().info(r -> r.message("KeelQueueTask to undeploy"));
notifyBeforeUndeploy();
return undeployMe().onSuccess(done -> {
this.queueWorkerPoolManager.whenOneWorkerEnds();
});
});
}
abstract protected Future run();
protected void notifyAfterDeployed() {
// do nothing by default
}
protected void notifyBeforeUndeploy() {
// do nothing by default
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy