title: Celery/Flask/Redis - apply_async function doesn't work - Updated 2
body: <p>everyone.</p>
  
  <pre><code>app.config['CELERY_BROKER_URL'] = 'redis://localhost:6379/0'
  app.config['CELERY_RESULT_BACKEND'] = 'redis://localhost:6379/0'
  
  celery = Celery(app.name, broker=app.config['CELERY_BROKER_URL'])
  celery.conf.update(app.config)
  
  
  def upload():
      if checkDouble == None:
          do_async_upload.apply_async(args=[checkDouble], countdown=15)
          return 'Saved ' + file.filename
      else:
          return "File exists"    
  
  @celery.task
  def do_async_upload(pic):
      print("hello2")
      db.session.add(pic)
      db.session.commit()
      return 0
  </code></pre>
  
  <p>But do_sync_upload doesn't work (hello2 doesn't print), it just skips. Redis server is working correctly</p>
  
  <p><strong>Updated:</strong></p>
  
  <pre><code>if checkDouble == None:
          print('Hello')
          async_result = do_async_upload.delay(checkDouble)
          print(async_result)
          result = async_result.get()
  
  
          return 'Saved ' + file.filename
      else:
          return "File exists"    
  </code></pre>
  
  <p>But do_async_upload.apply_async doesn't seem to execute at all.
  Maybe there is a problem in my Redis? Server is working, but after I try to submit something it turns from 0 to 4 clients connected.
  Or even I have a problem with my datetime settings.</p>
  
  <p><strong>UPDATE 2:</strong></p>
  
  <p>I tried 2 different examples with Flask and Celery and none of them work. Redis server shows some activity, but no.
  Both of them are using the same function:
  Code from <a href="https://github.com/ro6ley/flask-celery-demo" rel="nofollow noreferrer">https://github.com/ro6ley/flask-celery-demo</a>:</p>
  
  <pre><code>@client.task
  def send_mail(data):
  
      with app.app_context():
          msg = Message("Ping!",
                      sender="admin.ping",
                      recipients=[data['email']])
          msg.body = data['message']        
          mail.send(msg)
  
  
  @app.route('/', methods=['GET', 'POST'])
  def index():
      if request.method == 'GET':
          return render_template('index.html')
  
      elif request.method == 'POST':
          data = {}
          data['email'] = request.form['email']
          data['first_name'] = request.form['first_name']
          data['last_name'] = request.form['last_name']
          data['message'] = request.form['message']
          duration = int(request.form['duration'])
          duration_unit = request.form['duration_unit']
          print("1")    
          send_mail.apply_async(args=[data], countdown=duration)
          print("2")
          flash(f"Email will be sent to {data['email']} in {request.form['duration']} {duration_unit}")    
  </code></pre>
  
  <p>It shows flash message, but message isn't coming. Config.py is set correctly.</p>
  
  <p><strong>Next application:</strong></p>
  
  <pre><code> @app.route('/', methods=['GET', 'POST'])
      def index():
          if request.method == 'GET':
              return render_template('index.html', email=session.get('email', ''))
          email = request.form['email']
          session['email'] = email
  
          # send the email
          email_data = {
              'subject': 'Hello from Flask',
              'to': email,
              'body': 'This is a test email sent from a background Celery task.'
          }
          if request.form['submit'] == 'Send':
              # send right away
              send_async_email.delay(email_data)
              flash('Sending email to {0}'.format(email))
          else:
              # send in one minute
              send_async_email.apply_async(args=[email_data], countdown=60)
              flash('An email will be sent to {0} in one minute'.format(email))
  
          return redirect(url_for('index'))
  
      @celery.task
      def send_async_email(email_data):
          """Background task to send an email with Flask-Mail."""
          msg = Message(email_data['subject'],
                        sender=app.config['MAIL_DEFAULT_SENDER'],
                        recipients=[email_data['to']])
          msg.body = email_data['body']
          with app.app_context():
              mail.send(msg)
  </code></pre>
  
  <p>None of the options work.</p>