如果您不需要立即同步(即,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