Skip to content

Commit

Permalink
added an example code for worker dispatch (decorator)
Browse files Browse the repository at this point in the history
  • Loading branch information
phenobarbital committed Oct 26, 2022
1 parent bcc1188 commit 54e4cf8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
16 changes: 10 additions & 6 deletions examples/test_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,24 @@ async def send_email(sender):
)
await email.close()


if __name__ == '__main__':
loop = asyncio.get_event_loop()
asyncio.set_event_loop(loop)
async def create_user():
user = {
"name": "Jesus Lara",
"account": {
"address": "jesuslarag@gmail.com",
}
}
jesus = Actor(**user)
print(f'CREATING a NEW USER {user}')
sender = Actor(**user)
response = await send_email(sender)
print(f'WORKER RESPONSE: {response}')

if __name__ == '__main__':
loop = asyncio.get_event_loop()
asyncio.set_event_loop(loop)
try:
result = loop.run_until_complete(
send_email(sender=jesus)
create_user()
)
finally:
loop.stop()
13 changes: 13 additions & 0 deletions qw/utils/json.pyx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""
JSON Encoder, Decoder.
"""
import uuid
from asyncpg.pgproto import pgproto
from dataclasses import _MISSING_TYPE, MISSING
from typing import Any, Union
from decimal import Decimal
Expand All @@ -23,8 +25,19 @@ cdef class JSONContent:
return float(obj)
elif hasattr(obj, "isoformat"):
return obj.isoformat()
elif isinstance(obj, pgproto.UUID):
return str(obj)
elif isinstance(obj, uuid.UUID):
return obj
elif hasattr(obj, "hex"):
return obj.hex
elif hasattr(obj, 'lower'): # asyncPg Range:
up = obj.upper
if isinstance(up, int):
up = up - 1 # discrete representation
return [obj.lower, up]
elif hasattr(obj, 'tolist'): # numpy array
return obj.tolist()
elif isinstance(obj, _MISSING_TYPE):
return None
elif obj == MISSING:
Expand Down
2 changes: 1 addition & 1 deletion qw/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
__title__ = 'qworker'
__description__ = ('QueueWorker is asynchronous Task Queue implementation built on to of Asyncio.'
'Can you spawn distributed workers to run functions inside workers.')
__version__ = '1.3.2'
__version__ = '1.3.3'
__author__ = 'Jesus Lara'
__author_email__ = 'jesuslarag@gmail.com'
__license__ = 'MIT'
Expand Down

0 comments on commit 54e4cf8

Please sign in to comment.