aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Leon Sandøy <[email protected]>2020-05-24 15:21:35 +0200
committerGravatar Leon Sandøy <[email protected]>2020-05-24 15:21:35 +0200
commit66d273f0b8f1de6850760f4d561db446c027fdfe (patch)
tree9e5bb8bfe106227542399c4ee3839edf9212a969
parentMockBot needs to be aware of redis_ready (diff)
Add an option to use fakeredis in Bot.
Without this option, all contributors would need to set up a Redis server in order to run the bot. But with use_fakeredis set to True, this is no longer necessary because it will just set up a fakeredis redis pool instead of trying to contact an actual server. This is more than good enough for most local testing purposes, since data persistence across restarts isn't really relevant for them. This also means we need to move fakeredis into our real dependency list instead of having it as a dev dependency, so there's a minor change for that as well. I also made a small kaizen change to sort all the dependencies in the Pipfile alphabetically.
-rw-r--r--Pipfile28
-rw-r--r--Pipfile.lock58
-rw-r--r--bot/bot.py26
-rw-r--r--bot/constants.py1
-rw-r--r--config-default.yml1
5 files changed, 66 insertions, 48 deletions
diff --git a/Pipfile b/Pipfile
index cd2f2ad7a..b42ca6d58 100644
--- a/Pipfile
+++ b/Pipfile
@@ -4,30 +4,30 @@ verify_ssl = true
name = "pypi"
[packages]
-discord.py = "~=1.3.2"
+aio-pika = "~=6.1"
aiodns = "~=2.0"
aiohttp = "~=3.5"
-sphinx = "~=2.2"
-markdownify = "~=0.4"
-lxml = "~=4.4"
-pyyaml = "~=5.1"
+aioredis = "~=1.3.1"
+beautifulsoup4 = "~=4.9"
+colorama = {version = "~=0.4.3",sys_platform = "== 'win32'"}
+coloredlogs = "~=14.0"
+deepdiff = "~=4.0"
+discord.py = "~=1.3.2"
+fakeredis = "~=1.4"
+feedparser = "~=5.2"
fuzzywuzzy = "~=0.17"
-aio-pika = "~=6.1"
+lxml = "~=4.4"
+markdownify = "~=0.4"
+more_itertools = "~=8.2"
python-dateutil = "~=2.8"
-deepdiff = "~=4.0"
+pyyaml = "~=5.1"
requests = "~=2.22"
-more_itertools = "~=8.2"
sentry-sdk = "~=0.14"
-coloredlogs = "~=14.0"
-colorama = {version = "~=0.4.3",sys_platform = "== 'win32'"}
+sphinx = "~=2.2"
statsd = "~=3.3"
-feedparser = "~=5.2"
-beautifulsoup4 = "~=4.9"
-aioredis = "~=1.3.1"
[dev-packages]
coverage = "~=5.0"
-fakeredis = "~=1.4"
flake8 = "~=3.7"
flake8-annotations = "~=2.0"
flake8-bugbear = "~=20.1"
diff --git a/Pipfile.lock b/Pipfile.lock
index 1941f6887..0e591710c 100644
--- a/Pipfile.lock
+++ b/Pipfile.lock
@@ -1,7 +1,7 @@
{
"_meta": {
"hash": {
- "sha256": "c0b3e4d3e2c9ddb6ba28d2c09d521fe90ad4ea3df5c7ea7cd3a8b679fb3f85f9"
+ "sha256": "0297accc3d614d3da8080b89d56ef7fe489c28a0ada8102df396a604af7ee330"
},
"pipfile-spec": 6,
"requires": {
@@ -196,6 +196,14 @@
],
"version": "==0.16"
},
+ "fakeredis": {
+ "hashes": [
+ "sha256:4d170886865a91dbc8b7f8cbd4e5d488f4c5f2f25dfae127f001617bbe9e8f97",
+ "sha256:647b2593d349d9d4e566c8dadb2e4c71ba35be5bdc4f1f7ac2d565a12a965053"
+ ],
+ "index": "pypi",
+ "version": "==1.4.1"
+ },
"feedparser": {
"hashes": [
"sha256:bd030652c2d08532c034c27fcd7c85868e7fa3cb2b17f230a44a6bbc92519bf9",
@@ -501,6 +509,13 @@
"index": "pypi",
"version": "==5.3.1"
},
+ "redis": {
+ "hashes": [
+ "sha256:2ef11f489003f151777c064c5dbc6653dfb9f3eade159bcadc524619fddc2242",
+ "sha256:6d65e84bc58091140081ee9d9c187aab0480097750fac44239307a3bdf0b1251"
+ ],
+ "version": "==3.5.2"
+ },
"requests": {
"hashes": [
"sha256:43999036bfa82904b6af1d99e4882b560e5e2c68e5c4b0aa03b655f3d7d73fee",
@@ -531,6 +546,13 @@
],
"version": "==2.0.0"
},
+ "sortedcontainers": {
+ "hashes": [
+ "sha256:974e9a32f56b17c1bac2aebd9dcf197f3eb9cd30553c5852a3187ad162e1a03a",
+ "sha256:d9e96492dd51fae31e60837736b38fe42a187b5404c16606ff7ee7cd582d4c60"
+ ],
+ "version": "==2.1.0"
+ },
"soupsieve": {
"hashes": [
"sha256:1634eea42ab371d3d346309b93df7870a88610f0725d47528be902a0d95ecc55",
@@ -718,14 +740,6 @@
],
"version": "==0.3.0"
},
- "fakeredis": {
- "hashes": [
- "sha256:4d170886865a91dbc8b7f8cbd4e5d488f4c5f2f25dfae127f001617bbe9e8f97",
- "sha256:647b2593d349d9d4e566c8dadb2e4c71ba35be5bdc4f1f7ac2d565a12a965053"
- ],
- "index": "pypi",
- "version": "==1.4.1"
- },
"filelock": {
"hashes": [
"sha256:18d82244ee114f543149c66a6e0c14e9c4f8a1044b5cdaadd0f82159d6a6ff59",
@@ -735,11 +749,11 @@
},
"flake8": {
"hashes": [
- "sha256:6c1193b0c3f853ef763969238f6c81e9e63ace9d024518edc020d5f1d6d93195",
- "sha256:ea6623797bf9a52f4c9577d780da0bb17d65f870213f7b5bcc9fca82540c31d5"
+ "sha256:c69ac1668e434d37a2d2880b3ca9aafd54b3a10a3ac1ab101d22f29e29cf8634",
+ "sha256:ccaa799ef9893cebe69fdfefed76865aeaefbb94cb8545617b2298786a4de9a5"
],
"index": "pypi",
- "version": "==3.8.1"
+ "version": "==3.8.2"
},
"flake8-annotations": {
"hashes": [
@@ -805,10 +819,10 @@
},
"identify": {
"hashes": [
- "sha256:23c18d97bb50e05be1a54917ee45cc61d57cb96aedc06aabb2b02331edf0dbf0",
- "sha256:88ed90632023e52a6495749c6732e61e08ec9f4f04e95484a5c37b9caf40283c"
+ "sha256:0f3c3aac62b51b86fea6ff52fe8ff9e06f57f10411502443809064d23e16f1c2",
+ "sha256:f9ad3d41f01e98eb066b6e05c5b184fd1e925fadec48eb165b4e01c72a1ef3a7"
],
- "version": "==1.4.15"
+ "version": "==1.4.16"
},
"mccabe": {
"hashes": [
@@ -877,13 +891,6 @@
"index": "pypi",
"version": "==5.3.1"
},
- "redis": {
- "hashes": [
- "sha256:2ef11f489003f151777c064c5dbc6653dfb9f3eade159bcadc524619fddc2242",
- "sha256:6d65e84bc58091140081ee9d9c187aab0480097750fac44239307a3bdf0b1251"
- ],
- "version": "==3.5.2"
- },
"six": {
"hashes": [
"sha256:30639c035cdb23534cd4aa2dd52c3bf48f06e5f4a941509c8bafd8ce11080259",
@@ -898,13 +905,6 @@
],
"version": "==2.0.0"
},
- "sortedcontainers": {
- "hashes": [
- "sha256:974e9a32f56b17c1bac2aebd9dcf197f3eb9cd30553c5852a3187ad162e1a03a",
- "sha256:d9e96492dd51fae31e60837736b38fe42a187b5404c16606ff7ee7cd582d4c60"
- ],
- "version": "==2.1.0"
- },
"toml": {
"hashes": [
"sha256:926b612be1e5ce0634a2ca03470f95169cf16f939018233a670519cb4ac58b0f",
diff --git a/bot/bot.py b/bot/bot.py
index 0d423201b..f1365d532 100644
--- a/bot/bot.py
+++ b/bot/bot.py
@@ -7,6 +7,7 @@ from typing import Optional
import aiohttp
import aioredis
import discord
+import fakeredis.aioredis
from discord.ext import commands
from sentry_sdk import push_scope
@@ -48,11 +49,26 @@ class Bot(commands.Bot):
self.stats = AsyncStatsClient(self.loop, statsd_url, 8125, prefix="bot")
async def _create_redis_session(self) -> None:
- """Create the Redis connection pool, and then open the redis event gate."""
- self.redis_session = await aioredis.create_redis_pool(
- address=(constants.Redis.host, constants.Redis.port),
- password=constants.Redis.password,
- )
+ """
+ Create the Redis connection pool, and then open the redis event gate.
+
+ If constants.Redis.use_fakeredis is True, we'll set up a fake redis pool instead
+ of attempting to communicate with a real Redis server. This is useful because it
+ means contributors don't necessarily need to get Redis running locally just
+ to run the bot.
+
+ The fakeredis cache won't have persistence across restarts, but that
+ usually won't matter for local bot testing.
+ """
+ if constants.Redis.use_fakeredis:
+ log.info("Using fakeredis instead of communicating with a real Redis server.")
+ self.redis_session = await fakeredis.aioredis.create_redis_pool()
+ else:
+ self.redis_session = await aioredis.create_redis_pool(
+ address=(constants.Redis.host, constants.Redis.port),
+ password=constants.Redis.password,
+ )
+
self.redis_ready.set()
def add_cog(self, cog: commands.Cog) -> None:
diff --git a/bot/constants.py b/bot/constants.py
index 5d854dd7a..75d394b6a 100644
--- a/bot/constants.py
+++ b/bot/constants.py
@@ -208,6 +208,7 @@ class Redis(metaclass=YAMLGetter):
host: str
port: int
password: str
+ use_fakeredis: bool # If this is True, Bot will use fakeredis.aioredis
class Filter(metaclass=YAMLGetter):
diff --git a/config-default.yml b/config-default.yml
index 5be393463..cee955f20 100644
--- a/config-default.yml
+++ b/config-default.yml
@@ -7,6 +7,7 @@ bot:
host: "redis"
port: 6379
password: !ENV "REDIS_PASSWORD"
+ use_fakeredis: false
stats:
statsd_host: "graphite"