Skip to content

Commit

Permalink
🐳 chore: redis become optional
Browse files Browse the repository at this point in the history
  • Loading branch information
mic1on committed Nov 9, 2023
1 parent 5be799b commit 8efbcc0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ jobs:
key: venv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root
run: poetry install --no-interaction --no-root --all-extras
- name: Install library
run: poetry install --no-interaction
run: poetry install --no-interaction --all-extras
- name: Run tests
run: |
source .venv/bin/activate
Expand Down
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ asgiref = "^3.6.0"
blinker = "^1.5"
croniter = "^1.3.8"
usepy-plugin-rabbitmq = "^0.1.0"
usepy-plugin-redis = "^0.1.5"
usepy-plugin-redis = {version = "^0.1.6", optional = true}

[tool.poetry.extras]
redis = ["usepy-plugin-redis"]

[tool.poetry.group.dev.dependencies]
nacos-sdk-python = "^0.1.12"
Expand Down
11 changes: 6 additions & 5 deletions src/onestep/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
)
from .broker import (
BaseBroker, BaseConsumer, BaseLocalBroker, BaseLocalConsumer,
MemoryBroker, RabbitMQBroker, WebHookBroker, CronBroker
MemoryBroker, RabbitMQBroker, WebHookBroker, CronBroker, RedisStreamBroker
)
from .middleware import (
BaseMiddleware, BaseConfigMiddleware,
Expand All @@ -19,7 +19,7 @@

__all__ = [
'step',

# broker
'BaseBroker',
'BaseConsumer',
Expand All @@ -29,7 +29,8 @@
'RabbitMQBroker',
'WebHookBroker',
'CronBroker',

'RedisStreamBroker',

# retry
'BaseRetry',
'NeverRetry',
Expand All @@ -40,15 +41,15 @@
# error callback
'BaseErrorCallback',
'NackErrorCallBack',

# middleware
'BaseMiddleware',
'BaseConfigMiddleware',
'NacosPublishConfigMiddleware',
'NacosConsumeConfigMiddleware',
'RedisPublishConfigMiddleware',
'RedisConsumeConfigMiddleware',

# exception
'StopMiddleware',
'DropMessage',
Expand Down
7 changes: 5 additions & 2 deletions src/onestep/broker/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
from queue import Queue
from typing import Optional, Dict, Any

from usepy_plugin_redis import useRedisStreamStore, RedisStreamMessage
try:
from usepy_plugin_redis import useRedisStreamStore, RedisStreamMessage
except ImportError:
...

from .base import BaseBroker, BaseConsumer, Message

Expand Down Expand Up @@ -86,7 +89,7 @@ def requeue(self, message: Message, is_source=False):


class RedisStreamConsumer(BaseConsumer):
def _to_message(self, data: RedisStreamMessage):
def _to_message(self, data: "RedisStreamMessage"):
if "_message" in data.body:
# 来自 RedisStreamBroker.send 的消息,message.body 默认是存于 _message 字段中
try:
Expand Down

0 comments on commit 8efbcc0

Please sign in to comment.