- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我将使用 celery 设置周期性任务,以尝试使用脚本(在官方网站上引用)在测试服务器中守护 django celery 进程:
所以,这是我的 celeryd 文件:
# Names of nodes to start
# most people will only start one node:
CELERYD_NODES="indicators"
# but you can also start multiple and configure settings
# for each in CELERYD_OPTS (see `celery multi --help` for examples):
#CELERYD_NODES="worker1 worker2 worker3"
# alternatively, you can specify the number of nodes to start:
#CELERYD_NODES=10
# Absolute or relative path to the 'celery' command:
#CELERY_BIN="/usr/local/bin/celery"
CELERY_BIN="/opt/pymis/envs/indicators/indicators_test/bin/celery"
# App instance to use
# comment out this line if you don't use an app
#CELERY_APP="sgiprocess"
# or fully qualified:
CELERY_APP="indicator.tasks:app"
# Where to chdir at start.
CELERYD_CHDIR="/opt/pymis/reps/indicator_repository/indicator_ms/"
# Extra command-line arguments to the worker
CELERYD_OPTS="--time-limit=300 --concurrency=8"
# %N will be replaced with the first part of the nodename.
CELERYD_LOG_FILE="/var/log/celery/worker1.log"
CELERYD_PID_FILE="/var/run/celery/worker1.pid"
# Workers should run as an unprivileged user.
# You need to create this user manually (or you can choose
# a user/group combination that already exists, e.g. nobody).
CELERYD_USER="celeryuser"
CELERYD_GROUP="mygroup"
# If enabled pid and log directories will be created if missing,
# and owned by the userid/group configured.
CELERY_CREATE_DIRS=1
这是我的 celerybeat 文件:
# Absolute or relative path to the 'celery' command:
#CELERY_BIN="/usr/local/bin/celery"
CELERY_BIN="/opt/pymis/envs/indicators/indicators_test/bin/celery"
# App instance to use
# comment out this line if you don't use an app
#CELERY_APP="sgiprocess"
# or fully qualified:
CELERY_APP="indicator.tasks:app"
# Where to chdir at start.
CELERYBEAT_CHDIR="/opt/pymis/reps/indicators_repository/indicator_ms/"
# Extra arguments to celerybeat
CELERYBEAT_OPTS="--schedule=/var/run/celery/celerybeat-schedule"
这是我的错误轨迹:
(indicators_test) user@server:/opt/pymis/reps/indicator_repository/indicator_ms$ sudo /etc/init.d/celeryd restart
celery init v10.1.
Using config script: /etc/default/celeryd
celery multi v4.0.2 (latentcall)
Traceback (most recent call last):
File "/usr/lib/python3.5/runpy.py", line 184, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/opt/pymis/envs/indicators/indicators_test/lib/python3.5/site-packages/celery/__main__.py", line 18, in <module>
main()
File "/opt/pymis/envs/indicators/indicators_test/lib/python3.5/site-packages/celery/__main__.py", line 14, in main
_main()
File "/opt/pymis/envs/indicators/indicators_test/lib/python3.5/site-packages/celery/bin/celery.py", line 326, in main
cmd.execute_from_commandline(argv)
File "/opt/pymis/envs/indicators/indicators_test/lib/python3.5/site-packages/celery/bin/celery.py", line 488, in execute_from_commandline
super(CeleryCommand, self).execute_from_commandline(argv)))
File "/opt/pymis/envs/indicators/indicators_test/lib/python3.5/site-packages/celery/bin/base.py", line 279, in execute_from_commandline
argv = self.setup_app_from_commandline(argv)
File "/opt/pymis/envs/indicators/indicators_test/lib/python3.5/site-packages/celery/bin/base.py", line 481, in setup_app_from_commandline
self.app = self.find_app(app)
File "/opt/pymis/envs/indicators/indicators_test/lib/python3.5/site-packages/celery/bin/base.py", line 503, in find_app
return find_app(app, symbol_by_name=self.symbol_by_name)
File "/opt/pymis/envs/indicators/indicators_test/lib/python3.5/site-packages/celery/app/utils.py", line 355, in find_app
sym = symbol_by_name(app, imp=imp)
File "/opt/pymis/envs/indicators/indicators_test/lib/python3.5/site-packages/celery/bin/base.py", line 506, in symbol_by_name
return imports.symbol_by_name(name, imp=imp)
File "/opt/pymis/envs/indicators/indicators_test/lib/python3.5/site-packages/kombu/utils/imports.py", line 56, in symbol_by_name
module = imp(module_name, package=package, **kwargs)
File "/opt/pymis/envs/indicators/indicators_test/lib/python3.5/site-packages/celery/utils/imports.py", line 101, in import_from_cwd
return imp(module, package=package)
File "/opt/pymis/envs/indicators/indicators_test/lib/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 665, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "/opt/pymis/reps/indicator_repository/indicator_ms/indicator/tasks.py", line 7, in <module>
from .models import Value
File "/opt/pymis/reps/indicator_repository/indicator_ms/indicator/models.py", line 1, in <module>
from django.contrib.auth.models import User
File "/opt/pymis/envs/indicators/indicators_test/lib/python3.5/site-packages/django/contrib/auth/models.py", line 4, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/opt/pymis/envs/indicators/indicators_test/lib/python3.5/site-packages/django/contrib/auth/base_user.py", line 52, in <module>
class AbstractBaseUser(models.Model):
File "/opt/pymis/envs/indicators/indicators_test/lib/python3.5/site-packages/django/db/models/base.py", line 105, in __new__
app_config = apps.get_containing_app_config(module)
File "/opt/pymis/envs/indicators/indicators_test/lib/python3.5/site-packages/django/apps/registry.py", line 237, in get_containing_app_config
self.check_apps_ready()
File "/opt/pymis/envs/indicators/indicators_test/lib/python3.5/site-packages/django/apps/registry.py", line 124, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
> Restarting node indicators@EMT-LIBREAPP: * Child terminated with exit code 1
FAILED
事情是,当我手动启动 celery 和 celerybeat 时:
celery -A config worker -l info
celery -A config beat
我没有收到任何错误,一切都加载顺利。
更新:这是我的celery.py文件
from __future__ import absolute_import
from celery import Celery
from django.conf import settings
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings.test')
app = Celery('indicators')
app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
@app.task(bind=True)
def debug_task(self):
print('Request: {0!r}'.format(self.request))
更新 2:这是我的目录树
indicator_ms (project root)
├── config
│ ├── settings
│ │ ├── __init__.py
│ │ ├── local.py
│ │ ├── test.py
│ │ └── production.py
│ ├── __init__.py
│ ├── celery.py
│ ├── urls.py
│ └── wsgi.py
│
└── indicators (app)
├── __init__.py
└── tasks.py
这是配置文件夹(不是设置文件夹)中的init.py 文件
from __future__ import absolute_import
from .celery import app as celery_app
最佳答案
由于django celery 任务不是proyect 模块,我们需要调用django.setup()我们各自任务模块中的方法。
在我的例子中,解决方案是在任何其他项目相关导入之前在 task.py 文件中设置此行:
import django
django.setup()
关于Django celery 和 celery-beat 守护脚本错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41862694/
一 点睛 线程可以设置为守护线程,ThreadGroup 也可以设置为守护 ThreadGroup,但是若将一个 ThreadGroup 设置为 deamon,也并不会影响线程的 daemon 属性,
我有一个 python 脚本需要在启动时作为守护进程运行。进程从 tty(和 pdb)分离,但代码不运行。 我已经将它缩小到一个最小的例子 import daemon from time import
reactjs isMounted API 的文档提到: You can use this method to guard asynchronous calls to setState() or fo
我正在开发一个需要嵌入 HTTP 服务器的守护进程。我正在尝试使用 BaseHTTPServer 来完成它,当我在前台运行它时,它工作正常,但是当我尝试将守护进程 fork 到后台时,它停止工作。我的
我正在尝试使用 Apache Commons Daemon 使用 Daemon 接口(interface)来守护我的应用程序。 Java 应用程序本身不执行任何操作,只是写入 stout。 我编译了j
我正在使用 Bootle Python Web Framework 在 Ubuntu 上开发网络应用程序。是否有任何有效的方法来守护启动默认 bottlepy 网络服务器的脚本? 谢谢。 UPD:现在
我一直使用 bluepill成功地守护简单的 Ruby 脚本。然而这一次,我有一个脚本,它也在加载 Rails 环境,因此我可以访问 Rails 应用程序及其各自模型的数据库连接。我使用的 bluep
我试图守护一些代码,但我遇到了一些麻烦。 如果我用 tklogger() 调用代码,它运行得很好。但是,如果我在守护程序上下文中调用它,我会得到以下跟踪信息: Traceback (most rece
我打算使用 systemd 将 celery 4.3.0 作为守护进程运行,但它给了我这个错误: 它会启动 worker 但会很快停止它们。但是,我可以通过键入以下命令手动运行工作人员: celery
我是一名优秀的程序员,十分优秀!