title: Sequentially (serially) execute celery task, UNIQUE BY (args, task_id)
body: <p>I want to execute celery tasks sequentially (serially, one by one) UNIQUE BY (taskid, args).</p>
  <p>for example, we have Dockerfile and docker-compose.yml like these:</p>
  <pre><code>FROM python:3.8
  
  WORKDIR /usr/src/app
  
  ENV PYTHONDONTWRITEBYTECODE 1
  ENV PYTHONUNBUFFERED 1
  
  RUN pip install celery Redis flower
  COPY . .
  
  </code></pre>
  <pre class="lang-yaml prettyprint-override"><code>version: '3.3'
  
  services:
  
    handler:
      build: 
        context: .
        network: host
      ports:
        - 5000:5000
      command: python main.py
      volumes:
        - .:/usr/src/app
      environment:
        - CELERY_BROKER_URL=redis://redis:6379/0
        - CELERY_RESULT_BACKEND=redis://redis:6379/0
      depends_on:
        - redis
  
    worker:
      build: 
        context: .
        network: host
      command: celery --app main.app worker --uid=nobody --gid=nogroup --concurrency=1
      volumes:
        - .:/usr/src/app
      environment:
        - CELERY_BROKER_URL=redis://redis:6379/0
        - CELERY_RESULT_BACKEND=redis://redis:6379/0
      depends_on:
        - handler
        - redis
  
    redis:
      image: redis:6-alpine
  
  </code></pre>
  <p>and we have a python code like this:</p>
  <pre class="lang-py prettyprint-override"><code>import os
  import time
  from celery import Celery
  
  app = Celery(__name__)
  app.conf.broker_url = os.environ.get(
      &quot;CELERY_BROKER_URL&quot;, &quot;redis://localhost:6379&quot;
  )
  app.conf.result_backend = os.environ.get(
      &quot;CELERY_RESULT_BACKEND&quot;, &quot;redis://localhost:6379&quot;
  )
  
  @app.task()
  def add(x):
      time.sleep(10)
      return x + 10
  
  ret = add.apply_async(args=(1), task_id=&quot;foo&quot;) # no.1
  ret = add.apply_async(args=(1), task_id=&quot;foo&quot;) # no.2 it should be queued until no.1 finished
  ret = add.apply_async(args=(2), task_id=&quot;foo&quot;) # no.3 it should be executed asap because args is different from above
  ret = add.apply_async(args=(2), task_id=&quot;bar&quot;) # no.4 it should be executed asap because task_id is different from each of them
  
  </code></pre>
  <p>here is a task that return 10 + args(x) after sleeps 10sec.</p>
  <p>I want to execute tasks sequentially UNIQUE BY the pair of (task_id, args).</p>
  <p>is it possible? any opinions are welcomed.
  and also, I don't mind whether I use/don't use celery, so if there is an alternative way instead of celery, I'd love to know the idea.</p>