Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lock mechanism to prevent multiple task executions #228

Open
mcweba opened this issue Nov 29, 2024 · 0 comments
Open

Add lock mechanism to prevent multiple task executions #228

mcweba opened this issue Nov 29, 2024 · 0 comments

Comments

@mcweba
Copy link
Collaborator

mcweba commented Nov 29, 2024

When multiple instances of vertx-redisques are deployed and periodic tasks are scheduled, the tasks will be executed in every instance.

Example from PeriodicMetricsCollector class:

private void updateActiveQueuesCount(Runnable onPeriodicDone) {
    vertx.eventBus().request(redisquesAddress, buildGetQueuesCountOperation(), (Handler<AsyncResult<Message<JsonObject>>>) reply -> {
        if(reply.failed()) {
            log.warn("TODO error handling", reply.cause());
        } else if (reply.succeeded() && OK.equals(reply.result().body().getString(STATUS))) {
            activeQueuesCount.set(reply.result().body().getLong(VALUE));
        } else {
            log.warn("Error gathering count of active queues. Cause: {}", reply.result().body().getString(MESSAGE));
        }
        onPeriodicDone.run();
    });
}

Using the EventBus, the count of active queues is retrieved and stored in the counter. However, this task is executed by every instance concurrently. This is not very efficient, because counting queues takes some time and the result will most likely be the same for all the executions.

In swisspost/gateleen there is a class called LockUtil which provides a simple lock mechanism based on Redis to prevent concurrent executions of tasks.

This feature could also be introduced in vertx-redisques to improve handling of tasks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant