简体   繁体   English

自动化Python脚本的最佳方法

[英]Best way to automate Python script

I've got a number of scripts that move data from various data sources to BigQuery. 我有许多脚本可以将数据从各种数据源移到BigQuery。 Those scripts need to be run daily. 这些脚本需要每天运行。 I can't run it on my machine as it may be offline at the time when the script is to be run. 我无法在我的机器上运行它,因为在运行脚本时它可能处于脱机状态。

What service should i use to automate this and what should i look for when choosing one? 我应该使用哪种服务来实现这一自动化,选择一个时应该寻找什么? Is there anything like this within Google / Google Cloud environment? Google / Google Cloud环境中是否有类似的东西?

And how the process of automating the script once i have the server will look like? 以及一旦我拥有服务器,自动化脚本的过程将如何? Appreciate any advice or links to the docs. 感谢任何建议或文档链接。

You have two options: 您有两种选择:

  1. Spin up a GCE (or EC2) instance, and use a cron job to kick off your python scripts. 启动GCE(或EC2)实例,并使用cron作业启动python脚本。
  2. Forget about cron tabs, and use Apache Airflow (see links below). 忘记cron标签,并使用Apache Airflow(请参阅下面的链接)。

The latter would be my preferred weapon of choice. 后者将是我首选的选择武器。

https://airflow.incubator.apache.org/ https://airflow.incubator.apache.org/

http://engineering.pmc.com/2017/03/playing-around-with-apache-airflow-bigquery-62/ http://engineering.pmc.com/2017/03/playing-around-with-apache-airflow-bigquery-62/

https://medium.com/google-cloud/airflow-for-google-cloud-part-1-d7da9a048aa4 https://medium.com/google-cloud/airflow-for-google-cloud-part-1-d7da9a048aa4

Reliable Task Scheduling on Google Compute Engine you can use this and set daily execution time for script. 通过Google Compute Engine上可靠的任务计划,您可以使用它并设置脚本的每日执行时间。

Boto allows you to write some scripts to automate things like starting AWS EC2 instances Boto 宝途允许你写一些脚本像开始AWS EC2实例自动事情博托

Jenkins is a useful tool for this sort of thing. Jenkins是用于此类事情的有用工具。 It's meant for CI/CD but can be used to automate jobs at certain times or after certain conditions have been met. 它用于CI / CD,但可用于在特定时间或满足特定条件后自动执行作业。

Once you install it you access it through your browser at localhost:8080 and set up your build conditions. 安装后,您可以通过浏览器在localhost:8080对其进行访问并设置构建条件。

There's about a million plug-ins you can easily browse within the GUI so you should find something there to help. 您可以在GUI中轻松浏览大约一百万个插件,因此您应该在此找到帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM