title: Turn Off Celery Tasks
body: <p>I'm trying to find a way to be able to turn celery tasks on/off from the django admin.  This is mostly to disable tasks that call external services when those services are down or have a scheduled maintenance period.</p>
  
  <p>For my periodic tasks, this is easy, especially with django-celery.  But for tasks that are called on demand I'm having some trouble.  Currently I'm exploring just storing an on/off status for various tasks in a TaskControl model and then just checking that status at the beginning of task execution, returning None if the status is False.  This makes me feel dirty due to all the extra db lookups every time a task kicks off.  I could use a cache backend that isn't the db, but it seems a little overkill to add caching just for these handful of key/value pairs.  </p>
  
  <p>in models.py</p>
  
  <pre><code># this is a singleton model. singleton code bits omitted for brevity.
  class TaskControl(models.Model):
      some_status = models.BooleanField(default=True)
      # more statuses
  </code></pre>
  
  <p>in tasks.py</p>
  
  <pre><code>@celery.task(ignore_result=True)
  def some_task():
      task_control = TaskControl.objects.get(pk=1)
      if not task_control.some_status:
          return None
  
      # otherwise execute task as normal
  </code></pre>
  
  <p>What is a better way to do this?</p>