我需要跟踪其他网站的数据.由于它分布在60多页,我打算使用每日cron作业将任务添加到队列中.然后,此任务应该处理一个页面,并根据某些检查,将其自身的另一个实例放在下一页的队列中.
现在很简单
taskqueue.add(url='/path/to_self', params=control)
Run Code Online (Sandbox Code Playgroud)
在我的webapp.RequestHandler类的get中导致了这个任务
"POST /path/to_self HTTP/1.1" 405 -
Run Code Online (Sandbox Code Playgroud)
有没有办法让它工作,或者根本不可能从任务中向队列中添加任务?
我有一个谷歌应用引擎.当我向任务队列添加任务以发送电子邮件时.我有这个错误:
请求失败,因为URL要求用户登录.对于在App Engine中调用的请求(诸如任务队列之类的离线请求,或者像XMPP和传入邮件之类的webhook),URL必须要求管理员登录(或不登录).
我的命令是
taskqueue.add(url ='/ mypage/operation/task',params = {'key':operation.key()}
请帮我修理一下.
谢谢.
我正在使用python和Google应用引擎.我想使用任务队列.作为任务队列处理程序的一部分,我检查当前用户是否是管理员(使用用户服务).此测试总是失败.有没有办法让这个测试通过?
更新:为了避免进一步混淆,我试图找出触发任务的用户是否是管理员(这只是一个简单的例子).我知道该任务正在从服务器运行,所有用户cookie早已不复存在.所以我跳过的答案是将会话转移到任务的方法
import logging
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.api import taskqueue
class MyRequesHandler(webapp.RequestHandler):
def get(self):
taskqueue.add(url="/task/")
class MyTaskHandler(webapp.RequestHandler):
def post(self):
if users.is_current_user_admin():
logging.debug("admin")
else:
logging.debug("not admin")
def main():
logging.getLogger().setLevel(logging.DEBUG)
application = webapp.WSGIApplication([
('/', MyRequesHandler),
('/task/', MyTaskHandler)
],
debug=True)
run_wsgi_app(application)
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用类似于此示例的 RabbitMQ 在 PHP 上构建 RPC 服务:http: //www.rabbitmq.com/tutorials/tutorial-six-java.html 我正在使用此 PECL 扩展:http://pecl。 php.net/package/amqp(版本 1.0.3)
问题是,当我向服务器添加标志 AMQP_EXCLUSIVE 时,我的回调队列(在客户端脚本中声明)被锁定。
这是我的服务器
// connect to server
$cnn = new AMQPConnection('...');
$cnn->connect();
$channel = new AMQPChannel($cnn);
// create exchange
$exchangeName = 'k-exchange';
$exchange = new AMQPExchange($channel);
$exchange->setName($exchangeName);
$exchange->setType(AMQP_EX_TYPE_DIRECT);
$exchange->declare();
// declare queue to consume messages from
$queue = new \AMQPQueue($channel);
$queue->setName('tempQueue');
$queue->declare();
// start consuming messages
$queue->consume(function($envelope, $queue)
use ($channel, $exchange) {
// create callback queue
$callbackQueue = new \AMQPQueue($channel);
$callbackQueue->setName($envelope->getReplyTo());
$callbackQueue->setFlags(AMQP_EXCLUSIVE); // …Run Code Online (Sandbox Code Playgroud) 我有一个简单的Google App Engine应用程序,其中包含一个/update更新YouTube播放列表的页面.它看起来像这样:
class UpdatePage(webapp2.RequestHandler):
@decorator.oauth_required
def get(self):
update_result = self.update_playlist()
...
routes = [('/update', UpdatePage),
(decorator.callback_path, decorator.callback_handler())]
app = webapp2.WSGIApplication(routes, debug=True)
Run Code Online (Sandbox Code Playgroud)
它按预期update_playlist()工作,该方法完成其工作,但事实证明,在某些情况下,它可以运行很长一段时间,导致一个DeadlineExceededError.所以在阅读了可用的选项之后,我认为Task Queue API是要走的路(对吗?),我正在尝试使用它,遵循Python中的使用推送队列指南.
→简而言之,我分成UpdatePage了UpdatePageHandler+ UpdatePageWorker:
class UpdateHandlerPage(webapp2.RequestHandler):
@decorator.oauth_required
def get(self):
taskqueue.add(url='/updateworker')
class UpdateWorkerPage(webapp2.RequestHandler):
def post(self):
update_result = self.update_playlist()
...
routes = [('/update', UpdateHandlerPage),
('/updateworker', UpdateWorkerPage),
(decorator.callback_path, decorator.callback_handler())]
app = webapp2.WSGIApplication(routes, debug=True)
Run Code Online (Sandbox Code Playgroud)
不幸的是,在进行拆分后,我的OAuth2装饰器似乎不再起作用了:
INFO 2013-05-30 17:08:53,971 discovery.py:709] URL being requested: https://www.googleapis.com/youtube/v3/playlists?alt=json&part=snippet%2Cstatus
WARNING 2013-05-30 …Run Code Online (Sandbox Code Playgroud) python google-app-engine google-api task-queue google-api-python-client
我正在尝试将当前的GAE项目转换为使用模块.我希望特定路径的所有任务都在特定模块上运行.
我知道在生产中,我可以将任务排入正常状态,并且调度文件处理将其路由到正确的模块.
但是,如何在开发服务器中获得相同的行为?我宁愿不做一些像直接解决模块的hackey.
谢谢!
在这段视频(10:00) 中,这家伙说无限while (true);循环会阻止渲染,这会使 gif 停止动画。但是当我自己尝试代码时,我仍然无法选择段落文本,但是gif仍然是动画,我哪里误解了?我的代码和视频中的代码有什么区别?我的代码在这里:
<img src="https://media.giphy.com/media/3o85xsGXVuYh8lM3EQ/giphy.gif" alt="">
<button id="click">Click Me</button>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Quam saepe ratione possimus reiciendis ad ipsa architecto mollitia deserunt, delectus optio soluta quisquam magni ducimus sapiente vero. Cupiditate, et reprehenderit! Ea placeat sit a ab</p>
<script>
document.getElementById("click").addEventListener("click", ev => {
while (true) {
console.log("in the loop")
}
})
</script>Run Code Online (Sandbox Code Playgroud)
这个问题的直接答案是:行为实际上不同于 Chrome 和 Firefox(其他浏览器也是如此)。当我尝试使用 Firefox 时,gif 被阻止(如视频中所示),但在 Chrome 中,它仍在动画中。
我正在使用 Laravel Horizon 和 Redis,我正在尝试限制它。我使用的外部 API 的速率限制为每分钟 100 个请求。我需要提出大约 700 个请求。我进行了设置,以便添加到队列中的每个作业仅在作业本身中执行一个 API 调用。因此,如果我限制队列,我应该能够保持在限制范围内。由于某种原因,没有发生限制,而是超出了队列(当然,这会触发许多 API 错误)。然而,节流阀在本地工作,但不在我的服务器上工作。
我最初试图根据 Laravel 的队列文档进行限制,但只能让它在本地工作,所以我转而尝试Github 上的laravel-queue-rate-limit包。根据自述文件,我将以下内容添加到我的queue.php配置文件中:
'rateLimits' => [
'default' => [ // queue name
'allows' => 75, // 75 job
'every' => 60 // per 60 seconds
]
],
Run Code Online (Sandbox Code Playgroud)
由于某种原因,当我在本地 Ubuntu 环境中运行它时,限制可以正常工作,但它在我的服务器(也是 Ubuntu)上不起作用。在服务器上,它只是吹过队列,就好像没有适当的节流一样。
我是否做错了什么,或者可能有更好的方法来处理速率受限的外部 API?
编辑1:
配置/horizon.php
'environments' => [
'production' => [
'supervisor-1' => [
'connection' => 'redis',
'queue' => ['default'],
'balance' => 'simple',
'processes' => 3,
'tries' => 100,
], …Run Code Online (Sandbox Code Playgroud) 我正在尝试将压缩数据与任务队列中的任务一起使用,如下所示:
t = taskqueue.Task(url='/tasks/queue',
params={'param': zlib.compress(some_string)}
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试在队列处理程序中解压缩它时,就像这样
message = self.request.get('param')
message = zlib.decompress(message)
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
UnicodeEncodeError:'ascii'编解码器无法对位置2中的字符u'\ u06b8'进行编码:序数不在范围内(128)
谁知道这里发生了什么?有工作吗?
我做以下事情:
from google.appengine.ext import deferred
def send_message(client_id, message):
logging.info("sending message...")
class MyHandler(webapp.RequestHandler):
def get(self, field_name):
...
scUpdate = {
'val': value,
'name': field_name_converted
}
message = simplejson.dumps(scUpdate)
deferred.defer(send_message, client_id, message, _countdown=random.randrange(0, 5, 1))
Run Code Online (Sandbox Code Playgroud)
并得到
PermanentTaskFailure: 'module' object has no attribute 'send_message'
Run Code Online (Sandbox Code Playgroud)
这有什么不对?
UPD.看起来问题与那里描述的相同 - PermanentTaskFailure:'module'对象没有属性'Migrate' - 但我不明白如何解决这个问题.
task-queue ×10
python ×4
deferred ×1
devserver ×1
email ×1
event-loop ×1
google-api ×1
java ×1
javascript ×1
laravel ×1
locking ×1
module ×1
php ×1
rabbitmq ×1
redis ×1
task ×1
throttling ×1
zlib ×1