如何为 Cloud Composer 集群启动云代理
目前我们使用气流来管理作业和动态 DAG 创建。为此,编写一个单独的 Dag 来检查 PostgreSQL 中的数据库表是否存在现有规则,并且如果规则在 PostgreSQL 中处于活动/非活动状态,我们会在 Airflow 中手动设置关闭/打开动态 DAG。现在,我们将使用 Google 自己的托管 Cloud Composer,但问题是我们无权访问 Cloud Composer 的数据库。如何使用云sql代理来解决这个问题呢?
google-cloud-platform kubernetes cloud-sql-proxy google-cloud-composer
根据我的要求,我创建了一个结构体 -
type MyRule struct {
CreatedAt time.Time `json:"createdAt" datastore:"createdAt,noindex"`
UpdatedAt *time.Time `json:"updatedAt" datastore:"updatedAt,noindex"`
}
Run Code Online (Sandbox Code Playgroud)
对于createdAt字段,我可以将当前时间存储为-
MyRule.CreatedAt = time.Now()
Run Code Online (Sandbox Code Playgroud)
但是,同样的方法无法将当前时间存储在structupdatedAt字段中MyRule,因为它的类型为 is*time.Time和 not time.Time。在这里,我无法更改 的字段类型,updatedAt因为允许我在创建任何规则时*time.Time接受 nil 作为值。updatedAt
如果我尝试这样做-
MyRule.UpdatedAt = time.Now()
Run Code Online (Sandbox Code Playgroud)
它给了我以下错误-
cannot use time.Now()(type time.Time) as type *time.Time in assignment
Run Code Online (Sandbox Code Playgroud)
如何将当前时间值存储在类型为 *time.Time 而不是 time.Time 的 UpdatedAt 字段中
我无法将语句导入为-
from airflow.contrib.operators.gcp_sql_operator import CloudSqlQueryOperator
Run Code Online (Sandbox Code Playgroud)
我想将它导入到我的 DAG 文件中,该文件将在版本为 1.10.0 而不是 1.9.0 的云作曲家气流中运行。这里只是为了检查,我尝试将 gcs_to_gcs 导入为-
from airflow.contrib.operators.gcs_to_gcs import GoogleCloudStorageToGoogleCloudStorageOperator
Run Code Online (Sandbox Code Playgroud)
我可以导入它,但不能导入 gcp_sql_operator。