我通过supervisord开始芹菜,请参阅下面的条目.
[program:celery]
user = foobar
autostart = true
autorestart = true
directory = /opt/src/slicephone/cloud
command = /opt/virtenvs/django_slice/bin/celery beat --app=cloud -l DEBUG -s /home/foobar/run/celerybeat-schedule --pidfile=/home/foobar/run/celerybeat.pid
priority = 100
stdout_logfile_backups = 0
stderr_logfile_backups = 0
stdout_logfile_maxbytes = 10MB
stderr_logfile_maxbytes = 10MB
stdout_logfile = /opt/logs/celery.stdout.log
stderr_logfile = /opt/logs/celery.stderr.log
Run Code Online (Sandbox Code Playgroud)
pip冻结| grep芹菜
celery==3.1.0
Run Code Online (Sandbox Code Playgroud)
但任何用法:
@celery.task
def test_rabbit_running():
import logging
from celery.utils.log import get_task_logger
logger = get_task_logger(__name__)
logger.setLevel(logging.DEBUG)
logger.info("foobar")
Run Code Online (Sandbox Code Playgroud)
没有出现在日志中.相反,我得到如下条目.
celery.stdout.log
celery beat v3.1.0 (Cipater) is starting.
__ - ... __ - _
Configuration ->
. …Run Code Online (Sandbox Code Playgroud) 已经有很多帮助,但我仍然感到困惑.
我有一个像这样的unicode字符串:
title = u'test'
title_length = len(title) #5
Run Code Online (Sandbox Code Playgroud)
但!我需要len(标题)为6.客户希望它是6,因为它们似乎与我在后端的方式不同.
作为一种解决方法,我已经编写了这个小助手,但我确信它可以得到改进(有足够的编码知识)或者甚至可能是错误的.
title_length = len(title) + repr(title).count('\\U') #6
Run Code Online (Sandbox Code Playgroud)
1.有更好的方法将长度变为6吗?:-)
我假设我(Python)计算的unicode字符数为5.客户端计算字节数?
2.我的逻辑是否会破坏其他需要4个字节的unicode字符?
运行Python 2.7 ucs4.
我已经调用了一个任务,用urllib2远程获取一些信息几千次.这些任务是使用随机eta(一周内)安排的,因此它们都不会同时命中服务器.有时我会得到404,有时候不会.我正在处理错误,以防它发生.
在RabbitMQ控制台中,我可以看到16条未确认的消息: 
我停下芹菜,清理队列并重新启动它.16条未经确认的消息仍在那里.
我有其他任务进入同一队列,也没有执行任何任务.清除之后,我尝试提交另一项任务,状态仍然准备就绪:

我有什么想法可以找出为什么消息仍未被承认?
版本:
celery==3.1.4
{rabbit,"RabbitMQ","3.5.3"}
Run Code Online (Sandbox Code Playgroud)
celeryapp.py
CELERYBEAT_SCHEDULE = {
'social_grabber': {
'task': '<django app>.tasks.task_social_grabber',
'schedule': crontab(hour=5, minute=0, day_of_week='sunday'),
},
}
Run Code Online (Sandbox Code Playgroud)
tasks.py
@app.task
def task_social_grabber():
for user in users:
eta = randint(0, 60 * 60 * 24 * 7) #week in seconds
task_social_grabber_single.apply_async((user), countdown=eta)
Run Code Online (Sandbox Code Playgroud)
没有定义此任务的路由,因此它进入默认队列:celery.有一个工作人员处理此队列.
supervisord.conf:
[program:celery]
autostart = true
autorestart = true
command = celery worker -A <django app>.celeryapp:app --concurrency=3 -l INFO -n celery
Run Code Online (Sandbox Code Playgroud) 我有一个用Python 2.7编写的AWS Lambda函数,我想在其中执行以下操作:
1)从HTTP地址获取一个.xls文件。
2)将其存放在临时位置。
3)将文件存储在S3存储桶中。
我的代码如下:
from __future__ import print_function
import urllib
import datetime
import boto3
from botocore.client import Config
def lambda_handler(event, context):
"""Make a variable containing the date format based on YYYYYMMDD"""
cur_dt = datetime.datetime.today().strftime('%Y%m%d')
"""Make a variable containing the url and current date based on the variable
cur_dt"""
dls = "http://11.11.111.111/XL/" + cur_dt + ".xlsx"
urllib.urlretrieve(dls, cur_dt + "test.xls")
ACCESS_KEY_ID = 'Abcdefg'
ACCESS_SECRET_KEY = 'hijklmnop+6dKeiAByFluK1R7rngF'
BUCKET_NAME = 'my-bicket'
FILE_NAME = cur_dt + "test.xls";
data = open('/tmp/' + …Run Code Online (Sandbox Code Playgroud) 我有几个项目,都包含setup.py和requirements.txt。是否可以将整个项目打包在一个文件中,包括所有已编译并准备安装的要求?
我尝试过的:
python setup.py bdist_wheel
Run Code Online (Sandbox Code Playgroud)
构建一个.whl文件并将其放入dist目录中。轮子不包含任何依赖项。
pip wheel -r requirements.txt -w wheelhouse
Run Code Online (Sandbox Code Playgroud)
为每个需求构建轮子并将其放在wheelhouse目录中。例如,包括精心编译的代码numpy(我知道我必须在我希望它以后运行的每个平台上构建它,这很好)。
似乎我只是错过了最后一块拼图。
我已经从现有的 RDS PostgreSQL 数据库恢复了一个快照。现在我想重命名该数据库,但在 AWS 文档中的任何地方都找不到如何执行此操作。
我也找不到如何使用主密码(我希望让我这样做)。
我有几个虚拟主机的rabbitmq,每个都有几个队列.如何使用rabbitmqctl列出所有vhost中的所有队列?我试过了:
rabbitmqctl list_queues -p /*
rabbitmqctl list_queues -p *
rabbitmqctl list_queues -p /
rabbitmqctl list_queues -p ./*
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
到目前为止,这是我尝试过的:
from confluent_kafka import Consumer
c = Consumer({... several security/server settings skipped...
'auto.offset.reset': 'beginning',
'group.id': 'my-group'})
c.subscribe(['my.topic'])
msg = poll(30.0) # msg is of None type.
Run Code Online (Sandbox Code Playgroud)
msg几乎总是最终成为None这样。我认为问题可能是'my-group'已经消耗了所有消息'my.topic'......但我不在乎消息是否已经被消耗 - 我仍然需要最新的消息。具体来说,我需要最新消息的时间戳。
我又尝试了一些,从这里看来,该主题中可能有 25 条消息,但我不知道如何获取它们:
a = c.assignment()
print(a) # Outputs [TopicPartition{topic=my.topic,partition=0,offset=-1001,error=None}]
offsets = c.get_watermark_offsets(a[0])
print(offsets) # Outputs: (25, 25)
Run Code Online (Sandbox Code Playgroud)
如果因为该主题从未写入任何内容而没有消息,我该如何确定?如果是这样,我如何确定该主题存在了多长时间?我正在编写一个脚本,自动删除过去 X 天内未写入的任何主题(最初为 14 个 - 可能会随着时间的推移进行调整。)
python apache-kafka kafka-consumer-api confluent-platform confluent-kafka-python
当尝试运行测试(python manage.py test)时,我得到:
CommandError: Database test_db couldn't be flushed. Possible reasons:
* The database isn't running or isn't configured correctly.
* At least one of the expected database tables doesn't exist.
* The SQL was invalid.
Hint: Look at the output of 'django-admin.py sqlflush'. That's the SQL this command wasn't able to run.
The full error: cannot truncate a table referenced in a foreign key constraint
DETAIL: Table "install_location_2015_05_13" references "app".
HINT: Truncate table "install_location_2015_05_13" at the same time, or …Run Code Online (Sandbox Code Playgroud) python ×6
celery ×2
postgresql ×2
rabbitmq ×2
amazon-rds ×1
amazon-s3 ×1
apache-kafka ×1
atom-editor ×1
aws-lambda ×1
django ×1
logging ×1
pip ×1
python-2.7 ×1
python-wheel ×1
rabbitmqctl ×1
supervisord ×1
testing ×1
unicode ×1
urllib2 ×1