Merge pull request #730 from addo37/replyflow-commit
Prevent loss of DB state after bot termination
This commit is contained in:
commit
99e9b31f40
@ -3,9 +3,6 @@ package org.telegram.abilitybots.api.bot;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableList.Builder;
|
||||
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.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -193,6 +190,9 @@ public abstract class BaseAbilityBot extends DefaultAbsSender implements Ability
|
||||
.map(this::consumeUpdate)
|
||||
.forEach(this::postConsumption);
|
||||
|
||||
// Commit to DB now after all the actions have been dealt
|
||||
db.commit();
|
||||
|
||||
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));
|
||||
}
|
||||
@ -484,7 +484,6 @@ public abstract class BaseAbilityBot extends DefaultAbsSender implements Ability
|
||||
return user;
|
||||
});
|
||||
|
||||
db.commit();
|
||||
return update;
|
||||
}
|
||||
|
||||
|
@ -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.USER_NOT_FOUND;
|
||||
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.getLocalizedMessage;
|
||||
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));
|
||||
}
|
||||
})
|
||||
.post(commitTo(bot.db))
|
||||
.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());
|
||||
}
|
||||
})
|
||||
.post(commitTo(bot.db))
|
||||
.build();
|
||||
}
|
||||
|
||||
@ -339,7 +336,7 @@ public final class DefaultAbilities implements AbilityExtension {
|
||||
admins.add(userId);
|
||||
sendMd(ABILITY_PROMOTE_SUCCESS, ctx, escape(username));
|
||||
}
|
||||
}).post(commitTo(bot.db))
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
||||
@ -363,7 +360,6 @@ public final class DefaultAbilities implements AbilityExtension {
|
||||
sendMd(ABILITY_DEMOTE_FAIL, ctx, escape(username));
|
||||
}
|
||||
})
|
||||
.post(commitTo(bot.db))
|
||||
.build();
|
||||
}
|
||||
|
||||
@ -389,7 +385,6 @@ public final class DefaultAbilities implements AbilityExtension {
|
||||
send(ABILITY_CLAIM_SUCCESS, ctx);
|
||||
}
|
||||
})
|
||||
.post(commitTo(bot.db))
|
||||
.build();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user