-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New version: Task Streams via redis xgroups
- Loading branch information
1 parent
4a8586d
commit a4807d2
Showing
5 changed files
with
183 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import asyncio | ||
import time | ||
from qw.client import QClient, TaskWrapper | ||
from qw.utils import cPrint | ||
|
||
qw = QClient() | ||
|
||
print('SERVER : ', qw.get_servers()) | ||
|
||
|
||
async def very_long_task(seconds: int): | ||
if seconds == 17: | ||
raise ValueError('BAD BOYS') | ||
print(f'This Function Sleep for {seconds} sec.') | ||
await asyncio.sleep(seconds) | ||
|
||
|
||
async def queue_task(): | ||
await qw.publish(very_long_task, 10) | ||
task = TaskWrapper( | ||
program='troc', | ||
task='organizations', | ||
debug=True, | ||
ignore_results=True | ||
) | ||
res = await asyncio.gather( | ||
*[ | ||
qw.publish(task) | ||
] | ||
) | ||
print(f'Task Queued: {res!s}') | ||
await qw.publish(very_long_task, 15) | ||
|
||
if __name__ == '__main__': | ||
start_time = time.time() | ||
loop = asyncio.get_event_loop() | ||
top = loop.run_until_complete( | ||
queue_task() | ||
) | ||
end_time = time.time() - start_time | ||
cPrint(f'Task took {end_time} seconds to run', level='DEBUG') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters