Skip to content

Instantly share code, notes, and snippets.

@sisimaimai
Last active February 26, 2024 12:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sisimaimai/c71d27e2ab0e41b1452e7af1bb0feab1 to your computer and use it in GitHub Desktop.
Save sisimaimai/c71d27e2ab0e41b1452e7af1bb0feab1 to your computer and use it in GitHub Desktop.
main:
params: [args]
steps:
- transferAll:
parallel:
for:
value: device_id
in: ${args.device_ids}
steps:
- transferEach:
call: transferThermalInfo
args:
device_id: ${device_id}
transferThermalInfo:
params:
- device_id
steps:
# 温度情報の取得
- getThermalInfo:
try:
steps:
- executeRequest:
call: http.get
args:
url: {switchbot_thermal_getterでデプロイしたCloudFunctionのURL} # 要記載
query:
device_id: ${device_id}
auth:
type: OIDC
result: thermal_info_response
- printResponse:
call: sys.log
args:
data: ${thermal_info_response}
severity: INFO
retry:
predicate: ${http.default_retry_predicate_non_idempotent}
max_retries: 5
backoff:
initial_delay: 5
max_delay: 10
multiplier: 1.2
- printThermalInfo:
call: sys.log
args:
data: ${thermal_info_response.body}
severity: INFO
- decodeThermalInfo:
assign:
- thermal_info: ${json.decode(thermal_info_response.body)}
# Pub/Sub経由でBigQueryに送信
- printEncoded:
call: sys.log
args:
text: ${base64.encode(json.encode(thermal_info))}
severity: DEBUG
- transferToBigquery:
try:
call: googleapis.pubsub.v1.projects.topics.publish
args:
topic: {BigQueryサブスクリプションを設定したPubSubトピック} # 要記載
body:
messages:
- data: ${base64.encode(json.encode(thermal_info))}
result: publishResult
retry: ${http.default_retry}
- printPublishResult:
call: sys.log
args:
data: ${publishResult}
severity: INFO
- endTransfer:
call: sys.log
args:
text: '${"transfer " + device_id + " finished!"}'
severity: INFO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment