Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MongoDaoVerticle extends AbstractVerticle {
- private static final Logger logger = LoggerFactory.getLogger(MongoDaoVerticle.class);
- MongoClient platformMongoClient;
- private static final String LAST_SUCCESSFULL_EXECUTION_REQUEST = "{\"$and\": [ {\"executionId\" : \"%s\"} ," +
- " { \"$where\" : \"function() { " +
- " return this.executions.every( function(operation) {" +
- " return (operation.read.executionStatus === 'SUCCESS' " +
- " && operation.process.executionStatus === 'SUCCESS' " +
- " && operation.write.executionStatus === 'SUCCESS') " +
- " }) " +
- " }\"" +
- " } " +
- "] " +
- "}";
- @Override
- public void start() throws Exception {
- JsonObject rootConfig = config();
- JsonObject platformConfig = rootConfig.getJsonObject("mongo-platform");
- platformMongoClient = MongoClient.createShared(vertx, platformConfig, platformConfig.getString("pool_name"));
- vertx.eventBus().<JsonObject>consumer(EXECUTION_DAO_FIND_LAST_SUCCESSFUL, message -> {
- String executionId = message.body().getString("executionId");
- FindOptions options = new FindOptions() {{
- setLimit(1);
- setSort(new JsonObject().put("creationDate", -1));
- }};
- platformMongoClient.findWithOptions("executions", new JsonObject(String.format(LAST_SUCCESSFULL_EXECUTION_REQUEST, executionId)), options, event -> {
- if (event.failed()) {
- String errorMessage = "Find Error";
- logger.error(errorMessage, event.cause());
- message.fail(FIND_FAILURE, errorMessage);
- } else {
- message.reply(event.result().get(0));
- }
- });
- });
- }
- @Override
- public void stop() throws Exception {
- platformMongoClient.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment