- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
更新:我已经缩小了问题的范围,所以我删除了不必要的代码和示例:
更新 2:在让 cron 作业每隔 12 小时运行一段时间后(每次都成功结束,但 BQ 中没有任何内容)我们震惊地发现,大约一周后,其中一个 cron jobs 确实成功地写入了 BigQuery,同时 Stackdriver 日志指出“此请求导致为您的应用程序启动一个新进程(...)”,如下所示。以下作业再次停止写入。现在我想知道这是否以某种方式连接到缓存的应用程序状态(有一些有效期)或凭据到期日期以某种方式阻止在第一次之后进一步写入 BigQuery,但不会导致错误。
问题描述:
我正在尝试在 App Engine(标准)中设置一个 cron 作业以从 BigQuery 查询数据并将数据写回 BigQuery(数据集与已部署的应用程序位于同一项目中)并且 cron 作业成功执行但仅写入BigQuery 在部署后第一次执行,之后仍然执行成功但不写入。
我发现的主要区别是在 Stackdriver 日志中,对于正确写入的执行有额外的调试和信息,对于后续的执行没有这样的消息:
2018-04-19 04:44:03.933 CEST
Converted retries value: 3 -> Retry(total=3, connect=None, read=None, redirect=None, status=None) (/base/data/home/apps/e~<redacted>/lib/urllib3/util/retry.py:200)
2018-04-19 04:44:04.154 CEST
Making request: POST https://accounts.google.com/o/oauth2/token (/base/data/home/apps/e~<redacted>/lib/google/auth/transport/requests.py:117)
2018-04-19 04:44:04.160 CEST
Starting new HTTPS connection (1): accounts.google.com (/base/data/home/apps/e~<redacted>/lib/urllib3/connectionpool.py:824)
2018-04-19 04:44:04.329 CEST
https://accounts.google.com:443 "POST /o/oauth2/token HTTP/1.1" 200 None (/base/data/home/apps/e~<redacted>/lib/urllib3/connectionpool.py:396)
2018-04-19 04:44:04.339 CEST
Starting new HTTPS connection (1): www.googleapis.com (/base/data/home/apps/e~<redacted>/lib/urllib3/connectionpool.py:824)
2018-04-19 04:44:04.802 CEST
https://www.googleapis.com:443 "POST /bigquery/v2/projects/<redacted>/jobs HTTP/1.1" 200 None (/base/data/home/apps/e~<redacted>/lib/urllib3/connectionpool.py:396)
2018-04-19 04:44:04.813 CEST
This request caused a new process to be started for your application, and thus caused your application code to be loaded for the first time. This request may thus take longer and use more CPU than a typical request for your application.
我试过:
为默认应用引擎服务帐户添加 BigQuery DataOwner 和 User 权限,但没有效果。
有人提到标准应用引擎不完全支持 google.cloud 库,所以我尝试使用 OAuth2/httplib2/googleapiclient 凭据进行身份验证,但这是我第一次尝试,但我没有不明白如何将各个部分组合在一起,没有 google.cloud 库,我什至不知道如何为 BQ 编写正确的查询
下面建议的其他凭证设置方法,但似乎连接到 BQ 不是问题,它们都连接并写入(一次),只是在已部署的应用引擎中重复它。
下面是完整的实现:
应用程序.yaml:
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /bigquerycron
script: bigquerycron.app
login: admin
libraries:
- name: ssl
version: latest
env_variables:
GAE_USE_SOCKETS_HTTPLIB : 'true'
大查询cron.py
from __future__ import absolute_import
from google.cloud import bigquery
import webapp2
class MainPage(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
self.response.write('CRON test page')
def writeDataTest(dataset_id = '<redacted>',table_id='<redacted>'):
client = bigquery.Client.from_service_account_json("credentials.json")
job_config = bigquery.QueryJobConfig()
table_ref = client.dataset(dataset_id).table(table_id)
job_config.destination = table_ref
job_config.write_disposition = 'WRITE_APPEND'
query_job = client.query(
"""SELECT CURRENT_DATETIME() AS Datetime, 'CRON' as Source""", job_config=job_config)
writeDataTest()
app = webapp2.WSGIApplication([
('/bigquerycron', MainPage),
], debug=True)
cron.yaml:
cron:
- url: /bigquerycron
schedule: every 30 minutes
最佳答案
在此特定情况下,凭据不是问题,问题只是由于对 App Engine 工作方式的误解而导致函数调用的放置。 bigquery 的函数调用应该移动到 MainPage 类定义中,固定的 bigquerycron.py 看起来像这样(只移动了一行代码):
from __future__ import absolute_import
from google.cloud import bigquery
import webapp2
class MainPage(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
self.response.write('CRON test page')
writeDataTest()
def writeDataTest(dataset_id = '<redacted>',table_id='<redacted>'):
client = bigquery.Client.from_service_account_json("credentials.json")
job_config = bigquery.QueryJobConfig()
table_ref = client.dataset(dataset_id).table(table_id)
job_config.destination = table_ref
job_config.write_disposition = 'WRITE_APPEND'
query_job = client.query(
"""SELECT CURRENT_DATETIME() AS Datetime, 'CRON' as Source""", job_config=job_config)
app = webapp2.WSGIApplication([
('/bigquerycron', MainPage),
], debug=True)
OP 中的版本确实只向 BigQuery 写入一次,当第一次加载 App Engine 应用程序时,所有后续调用都只执行 MainPage 类,在这种情况下它什么都不做,因为实际的 BigQuery 代码在它之外。
此外,在不使用 GAE 标准 (https://github.com/GoogleCloudPlatform/google-cloud-python/issues/1893) 不支持的 google-cloud-python 库的情况下重写应用程序将是有益的。这尤其不幸,因为即使是 python 的官方 bigquery 文档(https://cloud.google.com/bigquery/docs/)也使用了这个库。但是,有多种解决方法可以继续使用它,包括链接的 github 问题中提到的一些方法以及此处: Using gcloud-python in GAE并且此示例中使用了类似的解决方法。
但如前所述,最好使用适用于 Python 的专用 Google API 客户端库: https://developers.google.com/api-client-library/python/
关于python-2.7 - Google App Engine 的 BigQuery cron 作业凭据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49812689/
Google Cloud Compute 中的 Google Compute Engine、App Engine 和 Container Engine 之间的实际区别是什么?什么时候使用什么? 有什么
我有一个在 Google App Engine 中运行的应用程序,它访问在 Google Compute Engine 中的机器上运行的服务。 Google App Engine 应用程序是该服务唯一
我们正在谷歌云中构建一个应用程序。我们使用 App Engine 作为前端,使用 Compute Engine 作为后端。在这些 Compute Engine 实例上,我正在运行一个接受特定“命令”消
我有一个现有的 GAE 应用程序(我们称之为应用程序 A)正在运行的情况,但由于非技术原因无法修改。当用户迁移到新的客户端版本时,我们需要将他们的数据从应用程序 A 迁移到新的 GAE 应用程序(我称
我正在尝试发现 App Engine 上的其他已部署服务。类似于 this文章建议。 我的代码是这样的: import ( "fmt" "net/http" "google.g
我想在我的网站上为“图像处理”事件设置服务器。如果我在 GCE 中使用“n1-standard-1”实例,GAE 中的可比功率是多少?是因为我算错了,还是同一个功率两者价格相差很大? 最佳答案 按小时
我在 Googl Compute Engine 和 Google App Engine 标准环境中的应用程序中创建了一个 VM 实例。我打算在 App Engine 中使用我的应用程序,在 Compu
我像往常一样使用 appcfg.py 更新我的应用程序,但收到一条错误消息。我试过 appcfg.py 回滚,两次尝试之间等了十分钟,但我仍然收到相同的错误消息。我该怎么办? 无法对 apps/dev
我想在 Google Compute Engine 上放置一个 Redis 服务器,并通过 AppEngine 的套接字支持与其对话。唯一的问题是似乎没有特定的防火墙规则说“此 AppEngine 应
我想知道 App Engine 和 Compute Engine 之间有什么区别。任何人都可以向我解释其中的区别吗? 最佳答案 App Engine 是一种平台即服务。这意味着您只需部署代码,平台会为
我正在编写一个在 App Engine 的 Go 运行时上运行的 Go 应用程序。 我注意到几乎所有使用 App Engine 服务(例如 Datastore、Mail 甚至 Capabilities
是否有人有在 Grid Engine/Sun Grid Engine/Son of Grid Engine 上运行 Docker 的经验,并且能够 monitor the resource used
我读了很多论坛,因为 grails app-engine 插件多年来没有更新,所以不可能将 grails 应用程序部署到谷歌应用程序引擎。当我准备放弃时,我发现使用 intellij 部署项目是可能的
当前设置, 运行 Windows Server 2012 (GCE Server 2012) 的谷歌计算引擎 运行 Debian Wheezy(GCE 服务器 Wheezy)的 Google 计算引擎
特定于基于 Docker 的部署,这两者之间有什么区别?由于 Google App Engine Flexible 现在也支持基于 Dockerfile 的部署,并且它也是完全托管的服务,因此它似乎比
我相信 Google Kubernetes Engine (GKE) 在 Google Compute Engine (GCE) 上运行。那么,在服务器管理方面使用 Google Kubernetes
TLDR;关于这个问题有任何更新吗? Google App Engine communicate with Compute Engine over internal network -- 是否可以在同
我正在尝试使用 Go SDK 为 App Engine 编写应用程序,但它似乎与单元测试有一种有趣的关系。人有written libraries左右this original, outdated一组工
在 App Engine 中,我想对在同一个 Google 云项目中创建的 Compute Engine 实例上运行的网络服务器进行 http fetch 调用,我想知道是否可以在不启用的情况下对实例
在编写 Go App Engine 标准应用程序时,过去的情况是您必须使用 App Engine SDK访问数据存储。然而,最近(从 Go 1.11 开始?),如果你只使用 Cloud Datasto
我是一名优秀的程序员,十分优秀!