Open cglotr opened 2 years ago
This is a great issue. The vision of this library is to be a comparable alternative to celery so we want to support most if not all of what celery supports, and pluggable dependencies.
You can install celery in these multiple ways for example, depending on your desired broker/transport:
$ pip install "celery[amqp]"
$ pip install "celery[amqp,redis,auth,msgpack]"
-- https://github.com/celery/celery#bundles
In our case we want to start simple so for this issue let's focus on pluggable broker (I intentionally use the term broker instead of cache since I think that's the more proper term here):
aiotaskq
with a specific implementation/bundle of the broker. pip install aiotaskq[redis]
will include the redis client. pip install aiotaskq
will default to redis. In the future we can add more implementation e.g. pip install aiotaskq[sqs]
, pip install aiotaskq[amqp]
, etc.aiotaskq
and use it the same way as it is now (without having to specify the broker manually).We should also try to learn from other python libraries how they support multiple pluggable dependencies, and borrow their implementations accordingly, but for now this is what we should focus on.
PR #31 Makes one step closer towards this with the usage of Golang-like interfaces (via typing.Protocol
)
Also, I'd like to a third item to the following list:
In our case we want to start simple so for this issue let's focus on pluggable broker (I intentionally use the term broker instead of cache since I think that's the more proper term here):
- Allow users to install aiotaskq with a specific implementation/bundle of the broker. pip install aiotaskq[redis] will include the redis client. pip install aiotaskq will default to redis. In the future we can add more implementation e.g. pip install aiotaskq[sqs], pip install aiotaskq[amqp], etc.
- Support dependency injection similar to the snippet in the issue desciption for easy unit testing, but make this injection invisible to the user, ie users still import aiotaskq and use it the same way as it is now (without having to specify the broker manually).
BROKER_URL=redis://127.0.0.1/ aiotaskq worker ...
vs BROKER_URL=memcached://127.0.0.1/ aiotaskq worker ...
Currently
aiotaskq
has a hard dependency on Redis making it hard to do unit testing & making it impossible for user code to use other key-value storage implementations https://github.com/imranariffin/aiotaskq/blob/cf6beae84a4ffc55d74bab193b854df2ffe039a8/src/aiotaskq/main.py#L95I think we should refactor the library to depend on interfaces & allow dependencies to be injected (dependency injection)
Below code snippet illustrates this point