事件触发器从Google Cloud运行python脚本 [英] Event trigger to run python script from Google Cloud

查看:144
本文介绍了事件触发器从Google Cloud运行python脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个读取csv文件的python脚本,基于csv中的数据在bigquery中创建表并在运行时将数据加载到表中。我想要在事件发生时触发此脚本,如到达指定存储桶的文件。我的Python脚本出现在vm实例上(直到现在,用于从vm实例运行脚本)。有什么方法可以基于事件触发器来执行这个脚本吗?

I have a python script which reads the csv file,create table in bigquery based on data in csv and loads the data into the table on runtime. I want to trigger this script whenever a event occurs like a file arriving on a specified bucket. My Python script is present on vm instance(till now,used to run the script from vm instance). Is there any way to execute this script based on a event trigger ?

推荐答案

Google云端存储的一项功能称为对象变更通知'可以在这里派上用场。这会将通知推送到Web钩子,您可以在其中使用处理代码处理事件(在AppEngine上运行此示例的示例被给出为这里,但你也可以实现这个例子作为一个Flask端点)。

A feature of Google Cloud Storage called 'Object Change Notifications' could come in handy here. This will push a notification to a web hook, where you can use your processing code to handle the event (an example to run this on AppEngine is given here, but you could also implement this as a Flask endpoint for example).

另一种选择是使用 Pub / Sub Notifications 与云存储相结合如果你对此更加舒服。然后,您可以使用 Pub / Sub Python SDK < a>收听您的活动到达的特定主题,并使用您已编写的代码处理这些活动。

Another option is to use Pub/Sub Notifications in combination with Cloud Storage, in case you are more comfortable with that. You can then use the Pub/Sub Python SDK to listen to a specific topic your events arrive in, and use the code you already wrote to handle these events.

这篇关于事件触发器从Google Cloud运行python脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆