0

Is it possible to set headers for one send_task but not the other? I noticed that send_task() doesn't have the posibility to set headers by default. I found https://stackoverflow.com/a/55718269/10306224, but that would add headers for all the tasks. Maybe I only missed something.. Thanks!

@app.task(
    bind=True,
    queue="dimensions-service",
    name="dimensions-service:persist",
    acks_late=True,
    task_reject_on_worker_lost=True,
    autoretry_for=(Exception,),
    retry_backoff=True,
    max_retries=3,
    task_time_limit=8,
)
@statsd.timed('persist_function.timer', use_ms=True)
def persister(
        self: Task,
        data: str
) -> None:
    # persist_data(data)

    # HERE I DON'T WANT TO SET HEADERS
    app.send_task(
        name="different_name",
        queue="different_queue",
        args=(data,)
    )
@app.task(
    bind=True,
    queue="dimensions-service",
    name="dimensions-service:check",
    acks_late=True,
    task_reject_on_worker_lost=True,
    autoretry_for=(Exception,),
    retry_backoff=True,
    max_retries=3,
    task_time_limit=8
)
@statsd.timed('check_function.timer', use_ms=True)
def check_if_exists(
        self: Task,
        data
) -> None:

    # HERE I WANT TO SET CUSTOM HEADER
    app.send_task(
        name="dimensions-service-measure:measure",
        queue="dimensions-service-measure",
        args=(data,)
    )
Leemosh
  • 883
  • 6
  • 19

1 Answers1

0

Nevermind, it actually works like this even it's not documented.

app.send_task(
    name="dimensions-service-measure:measure",
    queue="dimensions-service-measure",
    args=(data,),
    headers={"foo": "bar"}
)
Leemosh
  • 883
  • 6
  • 19