私信  •  关注

Dustin Ingram

Dustin Ingram 最近创建的主题
Dustin Ingram 最近回复了
4 年前
回复了 Dustin Ingram 创建的主题 » Google app engine正在使用python下载时重命名我的文件

你可以使用 save_as 参数来更改行为,当 True 它使用blob的文件名。

self.send_blob(file_object.blob, save_as=True)

"webapp Blobstore Handlers" 更多细节。

5 年前
回复了 Dustin Ingram 创建的主题 » 如何在python中处理传入的pubsub消息?

您需要创建一个长时间运行的进程,该进程可以连续轮询新消息(请求订阅)或具有可访问的端点以接收新消息(推送订阅)。

请参见此处的示例: https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/pubsub/cloud-client/subscriber.py ,以及推和拉之间的区别: https://cloud.google.com/pubsub/docs/subscriber

5 年前
回复了 Dustin Ingram 创建的主题 » 将git repo同步到谷歌云

如果您不需要立即同步(即,w/秒),可以设置一个 cron job 定期下拉 .zip 将你的报告存档,并上传到谷歌云存储。

在你的 app.yaml :

runtime: python37

在你的 cron.yaml :

cron:
- description: "sync from git repo"
  url: /tasks/sync
  schedule: every 1 minute

在你的 main.py :

from urllib.request import urlopen
from zipfile import ZipFile

from flask import Flask
from google.cloud import storage

app = Flask(__name__)

client = storage.Client(project='your-project-name')
bucket = client.get_bucket('your-bucket-name')

# Path to the archive of your repository's master branch
repo = 'https://github.com/your-username/your-repo-name/archive/master.zip'

@app.route('/tasks/sync')
def sync():
    with ZipFile(BytesIO(urlopen(repo).read())) as zipfile:
        for filename in zipfile.namelist():
            blob = storage.Blob(filename, bucket)
            blob.upload_from_string(zipfile.read(filename))

部署方式:

$ gcloud app deploy
$ gcloud app deploy cron.yaml