# NOT RUN {
# create build object
cloudbuild <- system.file("cloudbuild/cloudbuild_substitutions.yml",
package = "googleCloudRunner"
)
the_build <- cr_build_make(cloudbuild)
# this build includes substitution variables that read from pubsub message var1
the_build
# using googlePubSubR to create pub/sub topic if needed
# }
# NOT RUN {
library(googlePubsubR)
pubsub_auth()
topics_create("test-topic")
# }
# NOT RUN {
# create build trigger that will work from pub/subscription
pubsub_trigger <- cr_buildtrigger_pubsub("test-topic")
pubsub_trigger
# }
# NOT RUN {
cr_buildtrigger(the_build, name = "pubsub-triggered-subs", trigger = pubsub_trigger)
# }
# NOT RUN {
# make base64 encoded json for pubsub
library(jsonlite)
library(googlePubsubR)
# the message with the var1 that will be passed into the Cloud Build via substitution
message <- toJSON(list(var1 = "hello mum"))
# turning into JSON and encoding
send_me <- msg_encode(message)
# }
# NOT RUN {
# send a PubSub message with the encoded data message
topics_publish(PubsubMessage(send_me), "test-topic")
# did it work? After a while should see logs if it did
cr_buildtrigger_logs("pubsub-triggered-subs")
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab