강의

멘토링

커뮤니티

Inflearn Community Q&A

bluebamus's profile image
bluebamus

asked

Celery with a Silicon Valley Engineer

Learning about Tasks with Positional and Keyword arguments

group에서 keyword arg를 전송할 때에 대해 알고 싶습니다.

Written on

·

204

1

group에서 숏컷이 .s를 붙이면 되는 걸로 알고 있습니다.

이때, args와 kwargs가 같이 전송되어야 하는 경우 어떻게 해야 하는지 알고 싶습니다.

djangocelerydjango-celerydjango-celery-beat

Answer 1

0

altoformula님의 프로필 이미지
altoformula
Instructor

안녕하세요 bluebamus님

제가 코드 자료를 올리는 것을 깜박했나보네요 ㅠㅠ

https://github.com/dimz119/learn-celery/blob/main/django_celery/app/worker/celery_tasks/tasks.py#L61

여기를 확인해 보시면 될 듯 합니다.

다른 일반적인 예제는 예제는 이런 식으로 하시면 됩니다.

from celery import Celery
from celery import group

app = Celery('tasks', broker='pyamqp://guest@localhost//')

@app.task
def add(x, y, z=0):
    return x + y + z

# group에 전달할 개별 task 정의
tasks = group(
    add.s(1, 2, z=3),
    add.s(4, 5, z=6),
    add.s(7, 8, z=9)
)

result = tasks.apply_async()
bluebamus님의 프로필 이미지
bluebamus
Questioner

코드를 보니 바로 이해가 되었습니다 감사합니다.

bluebamus's profile image
bluebamus

asked

Ask a question