Google App Engine 实例可以为自己创建请求吗?
Can a Google App Engine Instance create a Request to itself?
我正在使用云任务对 App Engine 请求进行异步处理:
<app-engine-instance>/request -> <task_queue>/longrunning_task
我意识到我在复制很多代码,比如数据库模型。
一个更简单的解决方案是,如果我可以向自己发出请求
<app-engine-instance>/request -> <app-engine-instance>/longrunning_task
这怎么可能?
虽然复制代码听起来像是一个错误,但这是执行结合 AppEngine 和 Cloud Tasks 的操作的预期方式,尤其是对于较长的任务。
对 AppEngine 的请求是 limited to 60 seconds, while Cloud Tasks do not fall under such limitations. So, as already pointed out by guillaume blaquiere, if your long running task takes less than 60 seconds, you can perform a call from your code. Else, you have to use Cloud Task to handle long running tasks which is documented here。
For long-running jobs, we recommend usingCloud Tasks. With Cloud Tasks, HTTP requests are long-lived and return a response only after any asynchronous work ends.
话虽如此,AppEngine 实例可以向自己发送请求。但值得注意的是,AppEngine 的请求可能不会发送到发起请求的同一个实例,唯一会发生这种情况的情况是只有一个实例,通常这不是最佳做法。
我正在使用云任务对 App Engine 请求进行异步处理:
<app-engine-instance>/request -> <task_queue>/longrunning_task
我意识到我在复制很多代码,比如数据库模型。
一个更简单的解决方案是,如果我可以向自己发出请求
<app-engine-instance>/request -> <app-engine-instance>/longrunning_task
这怎么可能?
虽然复制代码听起来像是一个错误,但这是执行结合 AppEngine 和 Cloud Tasks 的操作的预期方式,尤其是对于较长的任务。
对 AppEngine 的请求是 limited to 60 seconds, while Cloud Tasks do not fall under such limitations. So, as already pointed out by guillaume blaquiere, if your long running task takes less than 60 seconds, you can perform a call from your code. Else, you have to use Cloud Task to handle long running tasks which is documented here。
For long-running jobs, we recommend usingCloud Tasks. With Cloud Tasks, HTTP requests are long-lived and return a response only after any asynchronous work ends.
话虽如此,AppEngine 实例可以向自己发送请求。但值得注意的是,AppEngine 的请求可能不会发送到发起请求的同一个实例,唯一会发生这种情况的情况是只有一个实例,通常这不是最佳做法。