英文:
GCP App Engine use for non web applications
问题
我有一个用例,我想在GCP上运行一个具有定时调度的应用程序。每隔X小时,我的 main.py
将执行一个函数,但我认为我不需要一个Web应用程序或使用Flask(这是我找到的示例)。
我尝试过使用函数框架,这在App Engine内是否是一个选择?(将函数框架的入口点作为应用程序的入口点)
从概念上看,我不确定App Engine是否是正确的前进方式,尽管它看起来是最简单的选项(不包括云函数,因为由于时间限制,我不能使用)。
谢谢!
英文:
I have a use case where I'd like to have an app running on GCP, with a schedule. Every X hours my main.py
would execute a function, but I think I am in no need of having a web app or use Flask (which are the examples I've found).
I did try to use the function-framework, would this be an option within App Engine? (have the function-framework entrypoint as the entrypoint for the app)
Conceptually I don't know if the app engine is the right way forward, although it does look like the simplest option (excluding cloud function which I can't use because of the time restrictions)
Thanks!
答案1
得分: 2
- You can use a Cloud Run Job (note that it's still in preview). As its documentation says:
> Unlike a Cloud Run service, which listens for and serves requests, a Cloud Run job <b>only runs its tasks and exits when finished</b>. A job does not listen for or serve requests, and cannot accept arbitrary parameters at execution.
-
You can also still use App Engine (Python + Flask). Using Cloud Scheduler, you schedule invoking a URL of your web app. However, because your task is long-running, you should use Cloud Tasks. Tasks allow you to run longer processes. Essentially, you'll have a 2-step process:
a. Cloud Scheduler invokes a URL on your GAE App.
b. This URL, in turn, pushes a task into your task queue, which then executes the task. This is a blog article (with sample code) we wrote for using tasks in GAE. It's for DJango, but you can easily replace it with Flask.
英文:
- You can use a Cloud Run Job (note that it's still in preview). As its documentation says
> Unlike a Cloud Run service, which listens for and serves requests, a Cloud Run job <b>only runs its tasks and exits when finished</b>. A job does not listen for or serve requests, and cannot accept arbitrary parameters at execution.
-
You can also still use App Engine (Python + Flask). Using Cloud Scheduler, you schedule invoking a url of your web app. However, because your task is long running, you should use Cloud Tasks. Tasks allow you run longer processes. Essentially, you'll have a 2 step process
a. Cloud Scheduler invokes a url on your GAE App.
b. This url in turn pushes a task into your task queue which then executes the task. This is a blog article (with sample code) we wrote for using tasks in GAE. It's for DJango but you can easily replace it with Flask.
答案2
得分: 1
如果您只需要运行一些后端逻辑,然后关闭直到下次运行,云函数适用于这种情况。
您可以设置云调度任务以定时调用该函数。
确保将该函数设置为对互联网保密,并配置一个用于云调度的服务帐户,该服务帐户具有调用私有函数的权限。
请注意函数配置选项以适应您的用例,具体信息请参阅 https://cloud.google.com/functions/docs/configuring,以及资源限制 https://cloud.google.com/functions/quotas#resource_limits。
有一个很好的教程来实现它:https://cloud.google.com/community/tutorials/using-scheduler-invoke-private-functions-oidc
英文:
If you just need to run some backend logic and then shutdown until the next run, cloud functions is done for that.
You can setup a cloud scheduler task to invoke the function on a time basis.
Make sure to keep the function private to the internet, as well as configuring a service account for the cloud scheduler to use with the rights to invoke the private function.
Be aware of functions configuration options to fit your use case https://cloud.google.com/functions/docs/configuring , as well as limits https://cloud.google.com/functions/quotas#resource_limits
Good turtorial to implement it: https://cloud.google.com/community/tutorials/using-scheduler-invoke-private-functions-oidc
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论