我已经将工作的Django应用程序部署在heroku上。整个应用程序以及芹菜任务都在本地环境中工作。但是当我在heroku中部署它时,任务没有运行。
当我手动打开heroku python manage.py shell
并从那里开始任务时,任务开始运行。当我单击页面上的按钮时,该任务实际上应该运行。那里不起作用。
参考文件:
myapp/celery.py
from __future__ import absolute_import, unicode_literals
from celery import Celery
import os
from vms.settings import USE_ELASTIC_SEARCH
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'vms.settings')
app = Celery('vms', broker=os.environ.get('REDIS_URL','redis://localhost'), include=['cve.tasks','cpe.tasks'])
app.conf.update(
result_backend='django-db',
result_expires=86400*2,
timezone = 'Asia/Kolkata'
)
if __name__ == '__main__':
app.start()
Procfile
web: gunicorn vms.wsgi
worker: celery -A vms worker -l info
[编辑] heroku日志中没有错误。
import os
import dj_database_url
import sys
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SECRET_KEY = 'blah blah'
DEBUG = True
ALLOWED_HOSTS = ["localhost","127.0.0.1","blahblah.herokuapp.com"]
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'vms',
'notifications',
'cpe',
'cve',
'products',
'django_celery_results',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'vms.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'django.template.context_processors.request',
],
},
},
]
WSGI_APPLICATION = 'vms.wsgi.application'
DATABASES = {
}
DATABASES['default'] = dj_database_url.config(default='mysql://root:toor@localhost:3306/vms')
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'Asia/Kolkata'
USE_I18N = True
USE_L10N = True
USE_TZ = True
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'staticfiles')
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(PROJECT_ROOT, 'static'),
)
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'
LOGIN_REDIRECT_URL = '/'
LOGIN_URL = '/accounts/login'
SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer'
USE_ELASTIC_SEARCH = os.environ.get('USE_ELASTIC_SEARCH','False') == 'True'
ELASTIC_SEARCH_URL = os.environ.get('ELASTICSEARCH_URL',"http://localhost:9200")