Skip to content

Commit

Permalink
fallback from multiple signals handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ivellios committed Sep 22, 2023
1 parent a5a3aab commit cf754ab
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 24 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,8 @@ As in `@receiver` decorator you can also pass a list of signals that the receive
```python
@receiver_task([profile_updated_signal, profile_deleted_signal])
```

# Limitations

For now this package does not support multiple signals passed to the `@receiver_task` decorator.
This may be added in the future.
8 changes: 2 additions & 6 deletions src/celery_signals/receivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def get_celery_app():


def receiver_task(
signal: typing.Union[UnifiedSignal, typing.Iterable[UnifiedSignal]],
signal: UnifiedSignal,
celery_task_options: typing.Optional[typing.Dict] = None,
**options,
):
Expand All @@ -59,11 +59,7 @@ def producer(
message_data = json.dumps(message.__dict__) if message else "{}"
return consumer.delay(message_data, *_args, **_kwargs)

if isinstance(signal, (list, tuple)):
for s in signal:
s.connect(producer, **options)
else:
signal.connect(producer, **options)
signal.connect(producer, **options)

return func

Expand Down
18 changes: 0 additions & 18 deletions tests/test_receivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,3 @@ def test_receivers_import_with_celery_app_defined_incorrectly():
get_celery_app()

settings.EVENT_SIGNALS_CELERY_APP = OLD_EVENT_SIGNALS_CELERY_APP


@override_settings(
CELERY_TASK_ALWAYS_EAGER=True, EVENT_SIGNALS_CELERY_APP="tests.testapp.celery.app"
)
def test_handling_multiple_signals():
signal_1 = UnifiedSignal(DataMock)
signal_2 = UnifiedSignal(DataMock)

@receiver_task([signal_1, signal_2], weak=False)
def handle_signal(sender, message, **kwargs):
if sender == "aaa":
assert message.field == 10
if sender == "bbb":
assert message.field == 5

signal_1.send("aaa", DataMock(field=10))
signal_2.send("bbb", DataMock(field=5))

0 comments on commit cf754ab

Please sign in to comment.