我对码头工人,芹菜和兔子相对较新.
在我们的项目中,我们目前有以下设置:1个运行多个docker容器的物理主机:
1x rabbitmq:3管理容器
# pull image from docker hub and install
docker pull rabbitmq:3-management
# run docker image
docker run -d -e RABBITMQ_NODENAME=my-rabbit --name some-rabbit -p 8080:15672 -p 5672:5672 rabbitmq:3-management
Run Code Online (Sandbox Code Playgroud)
1x芹菜容器
# pull docker image from docker hub
docker pull celery
# run celery container
docker run --link some-rabbit:rabbit --name some-celery -d celery
Run Code Online (Sandbox Code Playgroud)
(还有一些容器,但它们不应该对问题做任何事情)
任务文件
为了更好地了解celery和rabbitmq,我在物理主机上创建了一个tasks.py文件:
from celery import Celery
app = Celery('tasks', backend='amqp', broker='amqp://guest:guest@172.17.0.81/')
@app.task(name='tasks.add')
def add(x, y):
return x + y
Run Code Online (Sandbox Code Playgroud)
实际上整个设置似乎工作得很好.所以当我在tasks.py所在的目录中打开一个python shell并运行时
>>> from tasks import …Run Code Online (Sandbox Code Playgroud) 我只是将一个旧项目升级到 Python 3.6,并发现有这些很酷的新 async / await 关键字。
我的项目包含一个网络爬虫,目前性能不是很好,大约需要 7 分钟才能完成。现在,由于我已经安装了 django restframework 来访问我的 django 应用程序的数据,我认为拥有一个 REST 端点会很好,我可以通过一个简单的 POST 请求从远程启动爬虫。
但是,我不希望客户端同步等待爬虫完成。我只想直接给他发爬虫已经启动的消息,在后台启动爬虫。
from rest_framework import status
from rest_framework.decorators import api_view
from rest_framework.response import Response
from django.conf import settings
from mycrawler import tasks
async def update_all_async(deep_crawl=True, season=settings.CURRENT_SEASON, log_to_db=True):
await tasks.update_all(deep_crawl, season, log_to_db)
@api_view(['POST', 'GET'])
def start(request):
"""
Start crawling.
"""
if request.method == 'POST':
print("Crawler: start {}".format(request))
deep = request.data.get('deep', False)
season = request.data.get('season', settings.CURRENT_SEASON)
# this should be called async
update_all_async(season=season, deep_crawl=deep) …Run Code Online (Sandbox Code Playgroud) 我目前正在使用线程标题中提到的技术开展项目.
我从浏览器运行它(应用程序托管在heroku上),但是当我尝试从Ionic 2应用程序连接到websockets时,我总是在建立握手时出错.
2016-09-17T15:02:03.200133+00:00 app[web.1]: 2016-09-17 15:02:03,199 DEBUG Connection http.response!uvRVDyvolYEG did not get successful WS handshake.
2016-09-17T15:02:03.200498+00:00 app[web.1]: 2016-09-17 15:02:03,200 DEBUG WebSocket closed before handshake established
2016-09-17T15:02:03.169206+00:00 heroku[router]: at=info method=GET path="/1/" host=musicmashup-jukebox.herokuapp.com request_id=c46960d7-bb8f-45bf-b8be-5a934c771d96 fwd="212.243.230.222" dyno=web.1 connect=0ms service=7ms status=400 bytes=74
Run Code Online (Sandbox Code Playgroud)
现在有一个想法是,它可能是一个CORS问题.所以我安装django-cors-middleware希望这可以解决问题 - 好吧它没有.但我认为应用程序根本不会向Daphne服务器添加任何标头.
目前我不知道,如果问题出在客户端或服务器端.
有没有人遇到类似的问题?
编辑:发现websockets和CORS彼此没有任何关系为什么WebSockets没有同源策略?为什么我可以连接到ws:// localhost? 所以我的猜测是,服务器可能会拒绝客户端发送的原始标头.我会看看我是否可以抓住发送的标题
django django-rest-framework ionic-framework django-cors-headers django-channels
我目前在我的一个项目中遇到了一个非常奇怪的问题.
我在我的代码中实现了Tamir Gal的Sharp SSH库,以便每个FTP上传一些文件.当我在调试模式下运行代码时,一切正常.但是当我构建解决方案并使用该构建版本进行尝试时,我得到一个System.IO.IOException:
Tamir.SharpSsh.jsch.JSchException: Session.connect: System.IO.IOException: End of IO Stream Read at Tamir.SharpSsh.jsch.IO.getByte(Byte[] array, Int32 begin, Int32 length)
at Tamir.SharpSsh.jsch.Session.read(Buffer buf)
at Tamir.SharpSsh.jsch.User.Auth.start(Session session)
at Tamir.SharpSsh.jsch.UserAuthNone.start(Session session)
at Tamir.SharpSsh.jsch.Session.connect(Int32 connectTimeout)
at Tamir.SharpSsh.jsch.Session.connect(Int32 connectTimeout)
at Tamir.SharpSsh.jsch.SshBase.ConnectSession(Int32 tcpPort)
at Tamir.SharpSsh.jsch.SshBase.Connect(Int32 tcpPort)
at Tamir.SharpSsh.jsch.SshBase.Connect()
Run Code Online (Sandbox Code Playgroud)
看起来数据流存在问题(Hello Captain Obvious!:)),因此程序甚至没有建立完成连接方法.我只是不明白为什么一切都在调试时工作.dll在构建过程中被正确复制.
代码如下所示:
sftpClient = new Sftp(this.ftpHost, this.ftpUser, this.ftpPassword);
sftpClient.Connect();
Run Code Online (Sandbox Code Playgroud)
所有变量都具有正确的值,我可以在像Filezilla这样的客户端中使用它们连接到SFTP服务器.
如果有人能给我一个暗示或者有类似的问题,我会非常感谢每一条评论.
提前谢谢大家,祝你有个愉快的一天.
我想在我的 Angular 应用程序中使用 Polymers LitElement。
为此,我在应用程序test.js的assets文件夹中创建了一个示例组件 ( ) ,并将其导入到index.html.
测试.js:
// Import the LitElement base class and html helper function
import { LitElement, html } from '../../../node_modules/lit-element/lit-element';
// Extend the LitElement base class
class Test extends LitElement {
render(){
return html`
<h1>Test works!</h1>
`;
}
}
// Register the new element with the browser.
customElements.define('ti8m-test', Test);Run Code Online (Sandbox Code Playgroud)
索引.html:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>NgInAction</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" …Run Code Online (Sandbox Code Playgroud)我刚刚遇到一种情况,我希望在mixin的帮助下自动生成一系列css类.所以我想知道是否有办法动态地制作它.
基本上我有类似的课程
.tile-1, .tile-2, .tile-3, .tile-4 ...
Run Code Online (Sandbox Code Playgroud)
tile-2的高度是tile-1的高度的两倍,tile-3的高度是tile-1的高度的三倍,依此类推
我还创建了一个非常简单的mixin,可以在scss变量中设置base-height并从那里计算出来:
@mixin tile-height($size) {
height: $size * $tile-height;
}
Run Code Online (Sandbox Code Playgroud)
当$tile-height正在从另一个SCSS文件加载.
有没有办法在样式表中动态生成tile-x类,使用classname中的数字作为mixin参数?
我创建了一个页面选项卡Facebook应用程序,我想根据用户是否为粉丝显示不同的内容.(也称为扇形门,登陆页面或显示页面)
为此,我使用PHP SDK,具体如下代码:
<?php
require 'src/facebook.php';
$facebook = new Facebook(array(
'appId' => 'APP_ID',
'secret' => 'APP_SECRET',
'cookie' => true,
));
?>
Run Code Online (Sandbox Code Playgroud)
并在内容中:
<?php
$signed_request = $_REQUEST["signed_request"];
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
if (empty($data["page"]["liked"])) {?>
Thank you for liking our Page!
<?php } else { ?>
You haven't liked our page yet..
<?php };
// Debugging Code
echo "REQUEST:<br>";
print_r($_REQUEST);
echo "<br>GET:<br>";
print_r($_GET);
echo "<br>POST:<br>";
print_r($_POST);
?>
Run Code Online (Sandbox Code Playgroud)
当我使用我的Facebook用户登录并在我自己的页面上使用它时,这种方法有效.这意味着signed_request存在于$ _POST和$ _REQUEST中.
但是,当我用另一个用户测试它时,这些变量中没有signed_request值.
注意: - 我已经看了我的应用程序配置中的URL设置(300重定向和东西),但这看起来很好,就像我说我的用户它正在工作.. …
我正在尝试使用简单标记将数组传递给我的模板.我在app/templatetags/pages_navigation.py下创建了我的模块,在我看来代码应该没问题:
from django import template
from pages.models import Page
register = template.Library()
@register.simple_tag(name='links')
def pages_navigation():
pages = Page.objects.all()
links = [['Events','/']]
for page in pages:
links.append([page.title, '/'+page.url])
return {'links':links}
Run Code Online (Sandbox Code Playgroud)
在我的模板中,我尝试访问这样的链接:
<ul>
{% if links %}
{% for link in links %}
<a href="{{link.1}}"><li>{{link.0}}</li></a>
{% endfor %}
{% else %}
<li>no pages found</li>
{% endif%}
</ul>
Run Code Online (Sandbox Code Playgroud)
然而,不知何故,似乎链接总是空的.当我在python shell中尝试pages_navigation方法时,它工作得很好..
是否有可能无法从简单的标记方法返回数组?