Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: Fix README documentation #272

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ Publish and Subscribe with Celery
import celery
import celery_pubsub

@celery.task
@celery.shared_task
def my_task_1(*args, **kwargs):
return "task 1 done"


@celery.task
@celery.shared_task
def my_task_2(*args, **kwargs):
return "task 2 done"

Expand All @@ -43,16 +43,16 @@ def my_task_2(*args, **kwargs):
celery_pubsub.subscribe('some.topic', my_task_1)
celery_pubsub.subscribe('some.topic', my_task_2)

# Or subscribe with decoration
# Or subscribe with decorator + task decorator
@celery_pubsub.subscribe_to(topic="some.topic")
@celery.task
def my_task_1(*args, **kwargs):
return "task 1 done"
@celery.shared_task
def my_task_3(*args, **kwargs):
return "task 3 done"

# Or use only decoration
# Or use only `subscribe_to` decorator
@celery_pubsub.subscribe_to(topic="some.topic")
def my_task_1(*args, **kwargs):
return "task 1 done"
def my_task_4(*args, **kwargs):
return "task 4 done"

# Now, let's publish something
res = celery_pubsub.publish('some.topic', data='something', value=42)
Expand All @@ -70,17 +70,17 @@ res = celery_pubsub.publish('nowhere', data='something else', value=23)
Wildcards can be used in topic names:

* ``*`` matches any one group
* ``some.*.test`` will match ``some.awesome.test``, ``some.random.test``
but not ``some.pretty.cool.test``, ``elsewhere`` or ``here.some.up.test``
* ``some.*`` will match ``some.test`` and ``some.thing`` but it won't
match ``some`` or ``some.testy.test``
* ``some.*.test`` will match ``some.awesome.test``, ``some.random.test``
but not ``some.pretty.cool.test``, ``elsewhere`` or ``here.some.up.test``
* ``some.*`` will match ``some.test`` and ``some.thing`` but it won't
match ``some`` or ``some.testy.test``

* ``#`` matches any number of groups
* ``some.#.test`` will match ``some.awesome.test``, ``some.random.test``,
``some.pretty.cool.test`` but not ``elsewhere`` or ``here.some.up.test``
* ``some.#`` will match anything that starts with ``some.``, such as
``some.very.specific.topic.indeed``
* ``#`` will match anything
* ``some.#.test`` will match ``some.awesome.test``, ``some.random.test``,
``some.pretty.cool.test`` but not ``elsewhere`` or ``here.some.up.test``
* ``some.#`` will match anything that starts with ``some.``, such as
``some.very.specific.topic.indeed``
* ``#`` will match anything

```python
# Let's subscribe
Expand All @@ -94,17 +94,17 @@ celery_pubsub.subscribe('some.beep', my_task_6)

# or subscribe directly with decorator
@celery_pubsub.subscribe_to(topic="some.*")
def my_task_1(*args, **kwargs): ...
def my_task_7(*args, **kwargs): ...

@celery_pubsub.subscribe_to(topic="some.*.test")
def my_task_2(*args, **kwargs): ...
def my_task_8(*args, **kwargs): ...

# Let's publish
celery_pubsub.publish('nowhere', 4) # task 4 only
celery_pubsub.publish('some', 8) # task 4 only
celery_pubsub.publish('some.thing', 15) # tasks 1, 3 and 4
celery_pubsub.publish('some.true.test', 16) # tasks 2, 3 and 4
celery_pubsub.publish('some.beep', 23) # tasks 1, 3, 4, 5 and 6
celery_pubsub.publish('some.thing', 15) # tasks 1, 3, 4 and 7
celery_pubsub.publish('some.true.test', 16) # tasks 2, 3, 4 and 8
celery_pubsub.publish('some.beep', 23) # tasks 1, 3, 4, 5, 6 and 7
celery_pubsub.publish('some.very.good.test', 42) # tasks 3 and 4

# And if you want to publish synchronously:
Expand Down