Merge pull request #730 from addo37/replyflow-commit

Prevent loss of DB state after bot termination
This commit is contained in:
Ruben Bermudez 2020-04-26 01:57:07 +01:00 committed by GitHub
commit 99e9b31f40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 10 deletions

View File

@ -3,9 +3,6 @@ package org.telegram.abilitybots.api.bot;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableList.Builder; import com.google.common.collect.ImmutableList.Builder;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Multimap;
import org.apache.commons.io.IOUtils;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -193,6 +190,9 @@ public abstract class BaseAbilityBot extends DefaultAbsSender implements Ability
.map(this::consumeUpdate) .map(this::consumeUpdate)
.forEach(this::postConsumption); .forEach(this::postConsumption);
// Commit to DB now after all the actions have been dealt
db.commit();
long processingTime = System.currentTimeMillis() - millisStarted; long processingTime = System.currentTimeMillis() - millisStarted;
log.info(format("[%s] Processing of update [%s] ended at %s%n---> Processing time: [%d ms] <---%n", botUsername, update.getUpdateId(), now(), processingTime)); log.info(format("[%s] Processing of update [%s] ended at %s%n---> Processing time: [%d ms] <---%n", botUsername, update.getUpdateId(), now(), processingTime));
} }
@ -484,7 +484,6 @@ public abstract class BaseAbilityBot extends DefaultAbsSender implements Ability
return user; return user;
}); });
db.commit();
return update; return update;
} }

View File

@ -60,7 +60,6 @@ import static org.telegram.abilitybots.api.util.AbilityMessageCodes.ABILITY_UNBA
import static org.telegram.abilitybots.api.util.AbilityMessageCodes.ABILITY_UNBAN_SUCCESS; import static org.telegram.abilitybots.api.util.AbilityMessageCodes.ABILITY_UNBAN_SUCCESS;
import static org.telegram.abilitybots.api.util.AbilityMessageCodes.USER_NOT_FOUND; import static org.telegram.abilitybots.api.util.AbilityMessageCodes.USER_NOT_FOUND;
import static org.telegram.abilitybots.api.util.AbilityUtils.addTag; import static org.telegram.abilitybots.api.util.AbilityUtils.addTag;
import static org.telegram.abilitybots.api.util.AbilityUtils.commitTo;
import static org.telegram.abilitybots.api.util.AbilityUtils.escape; import static org.telegram.abilitybots.api.util.AbilityUtils.escape;
import static org.telegram.abilitybots.api.util.AbilityUtils.getLocalizedMessage; import static org.telegram.abilitybots.api.util.AbilityUtils.getLocalizedMessage;
import static org.telegram.abilitybots.api.util.AbilityUtils.shortName; import static org.telegram.abilitybots.api.util.AbilityUtils.shortName;
@ -288,7 +287,6 @@ public final class DefaultAbilities implements AbilityExtension {
sendMd(ABILITY_BAN_SUCCESS, ctx, escape(bannedUser)); sendMd(ABILITY_BAN_SUCCESS, ctx, escape(bannedUser));
} }
}) })
.post(commitTo(bot.db))
.build(); .build();
} }
@ -315,7 +313,6 @@ public final class DefaultAbilities implements AbilityExtension {
bot.silent.sendMd(getLocalizedMessage(ABILITY_UNBAN_SUCCESS, ctx.user().getLanguageCode(), escape(username)), ctx.chatId()); bot.silent.sendMd(getLocalizedMessage(ABILITY_UNBAN_SUCCESS, ctx.user().getLanguageCode(), escape(username)), ctx.chatId());
} }
}) })
.post(commitTo(bot.db))
.build(); .build();
} }
@ -339,7 +336,7 @@ public final class DefaultAbilities implements AbilityExtension {
admins.add(userId); admins.add(userId);
sendMd(ABILITY_PROMOTE_SUCCESS, ctx, escape(username)); sendMd(ABILITY_PROMOTE_SUCCESS, ctx, escape(username));
} }
}).post(commitTo(bot.db)) })
.build(); .build();
} }
@ -363,7 +360,6 @@ public final class DefaultAbilities implements AbilityExtension {
sendMd(ABILITY_DEMOTE_FAIL, ctx, escape(username)); sendMd(ABILITY_DEMOTE_FAIL, ctx, escape(username));
} }
}) })
.post(commitTo(bot.db))
.build(); .build();
} }
@ -389,7 +385,6 @@ public final class DefaultAbilities implements AbilityExtension {
send(ABILITY_CLAIM_SUCCESS, ctx); send(ABILITY_CLAIM_SUCCESS, ctx);
} }
}) })
.post(commitTo(bot.db))
.build(); .build();
} }