server.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:scrappy-serverless 作者: beardedfoo 项目源码 文件源码
def add_fn(fn):
    with open('/tmp/handler.py', 'w') as f:
        f.write(request.form['code'])

    with open('/tmp/Dockerfile', 'w') as f:
        f.write('FROM scrappy-serverless\n')
        f.write('WORKDIR /worker\n')
        f.write('COPY handler.py /worker/handler.py\n')
        f.write('CMD rq worker -u redis://redis -b ' + fn)

    out = subprocess.check_output(['docker', 'build', '-t', 'serverless/'+fn, '/tmp'])

    for line in out.split('\n'):
        if line.startswith('Successfully built'):
            image_id = line.split()[2]
            break
    else:
        raise RuntimeError('bad build')

    images[fn] = image_id
    return 'OK ' + image_id

# PLAN: Call existing functions @ GET /api/<fn>
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号