-
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.
fix: Fix
get
command in the result attribute, and add `get_group_ta…
…sks` (#11)
- Loading branch information
Showing
21 changed files
with
285 additions
and
195 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
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,8 @@ | ||
# Examples of usage of Retsu | ||
|
||
This folder contains some examples of usage of Retsu. | ||
|
||
## Using redis as a queue between celery tasks | ||
|
||
The `redis_queue_between_tasks` folder contains an example about how to create | ||
extra queues to establish communication across different celery chord tasks. |
File renamed without changes.
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,11 @@ | ||
# How to test | ||
|
||
You can run `run.sh` in your terminal, and in the web browser you can try the | ||
following endpoints: | ||
|
||
- http://127.0.0.1:5000/serial/10/20 | ||
- http://127.0.0.1:5000/parallel/10/20 | ||
- http://127.0.0.1:5000/serial/result/[TASK_ID] | ||
- http://127.0.0.1:5000/parallel/result/[TASK_ID] | ||
|
||
Remember to replace `[TASK_ID]` by the desired task id. |
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -ex | ||
|
||
pushd ../../ | ||
|
||
sugar build | ||
sugar ext restart --options -d | ||
sleep 5 | ||
|
||
popd | ||
|
||
celery -A tasks.app worker --loglevel=debug & | ||
python app.py |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,66 @@ | ||
"""My retsu tasks.""" | ||
|
||
from __future__ import annotations | ||
|
||
from time import sleep | ||
|
||
import celery | ||
|
||
from retsu.celery import ParallelCeleryTask | ||
|
||
from .config import app, redis_client | ||
|
||
|
||
@app.task | ||
def task_parallel_a_plus_b(a: int, b: int, task_id: str) -> int: # type: ignore | ||
"""Define the task_parallel_a_plus_b.""" | ||
sleep(a + b) | ||
print("running task_parallel_a_plus_b") | ||
result = a + b | ||
redis_client.set(f"parallel-result-a-plus-b-{task_id}", result) | ||
return result | ||
|
||
|
||
@app.task | ||
def task_parallel_result_plus_10(task_id: str) -> int: # type: ignore | ||
"""Define the task_parallel_result_plus_10.""" | ||
print("running task_parallel_result_plus_10") | ||
result = None | ||
while result is None: | ||
result = redis_client.get(f"parallel-result-a-plus-b-{task_id}") | ||
sleep(1) | ||
|
||
final_result = int(result) + 10 | ||
redis_client.set(f"parallel-result-plus-10-{task_id}", final_result) | ||
return final_result | ||
|
||
|
||
@app.task | ||
def task_parallel_result_square(results, task_id: str) -> int: # type: ignore | ||
"""Define the task_parallel_result_square.""" | ||
print("running task_parallel_result_square") | ||
result = None | ||
while result is None: | ||
result = redis_client.get(f"parallel-result-plus-10-{task_id}") | ||
sleep(1) | ||
return int(result) ** 2 | ||
|
||
|
||
class MyParallelTask1(ParallelCeleryTask): | ||
"""MyParallelTask1.""" | ||
|
||
def request(self, a: int, b: int) -> str: | ||
"""Receive the request for processing.""" | ||
return super().request(a=a, b=b) | ||
|
||
def get_chord_tasks( | ||
self, a: int, b: int, task_id: str | ||
) -> list[celery.Signature]: | ||
"""Define the list of tasks for celery chord.""" | ||
return ( | ||
[ | ||
task_parallel_a_plus_b.s(a, b, task_id), | ||
task_parallel_result_plus_10.s(task_id), | ||
], | ||
task_parallel_result_square.s(task_id), | ||
) |
Oops, something went wrong.