title: Register Celery Class-based Task
body: <p>Python 3.x, Celery 4.x...</p>
  
  <p>I have a class-based task.</p>
  
  <p><code>myproj/celery.py</code></p>
  
  <pre><code>from celery import Celery
  
  # django settings stuff...
  
  app = Celery('myproj')
  app.autodiscover_tasks()
  </code></pre>
  
  <p><code>app1/tasks.py</code></p>
  
  <pre><code>import celery
  
  class EmailTask(celery.Task):
      def run(self, *args, **kwargs):
          self.do_something()
  </code></pre>
  
  <p>If I do:</p>
  
  <pre><code>$ celery worker -A myproj -l info
  [tasks]
    . app2.tasks.debug_task
    . app2.tasks.test
  </code></pre>
  
  <p>So, the celery decorators work to register tasks, but the class-based task is not registered.</p>
  
  <h1>How do I get the class-based tasks to register?</h1>
  
  <p><strong>Update 1:</strong></p>
  
  <p>If I add the following lines to <code>app1/tasks.py</code></p>
  
  <pre><code>from myproj.celery import app
  email_task = app.tasks[EmailTask.name]
  </code></pre>
  
  <p>.</p>
  
  <pre><code>$ celery worker -A myproj -l info
    File "myproj/app1/tasks.py", line 405, in &lt;module&gt;
      email_task = app.tasks[EmailTask.name]
    File "/usr/local/lib/python3.5/site-packages/celery/app/registry.py", line 19, in __missing__
      raise self.NotRegistered(key)
  celery.exceptions.NotRegistered
  </code></pre>
  
  <p><strong>Update 2:</strong></p>
  
  <p>I am able to execute my task synchronously (<code>run</code>) via a wrapper. However, I cannot run the task async, i.e., via <code>delay</code>.</p>
  
  <p><code>app1/tasks.py</code></p>
  
  <pre><code>@app.task
  def email_task():
      """
      Wrapper to call class based task
      """
      task = EmailTask()
      # task.delay()  # Won't work!!!
      task.run()
  </code></pre>
  
  <p>.</p>
  
  <pre><code>$./manage.py shell
  &gt; from app1.tasks import EmailTask
  &gt; task1 = EmailTask()
  &gt; task1.run() # a-okay
  &gt; task2 = EmailTask()
  &gt; task2.delay() # nope
    &lt;AsyncResult: 1c03bad9-169a-4a4e-a56f-7d83892e8bbc&gt;
  
  # And on the worker...
  [2017-01-22 08:07:28,120: INFO/PoolWorker-1] Task app1.tasks.email_task[41e5bc7d-058a-400e-9f73-c853c0f60a2a] succeeded in 0.0701281649817247s: None
  [2017-01-22 08:10:31,909: ERROR/MainProcess] Received unregistered task of type None.
  The message has been ignored and discarded.
  </code></pre>