# NOT RUN {
cloudbuild <- system.file("cloudbuild/cloudbuild.yaml", package = "googleCloudRunner")
build1 <- cr_build_make(cloudbuild)
build1
# }
# NOT RUN {
cr_schedule("cloud-build-test1",
schedule = "15 5 * * *",
httpTarget = cr_schedule_http(build1)
)
# a cloud build you would like to schedule
itworks <- cr_build("cloudbuild.yaml", launch_browser = FALSE)
# once working, pass in the build to the scheduler
cr_schedule("itworks-schedule",
schedule = "15 5 * * *",
httpTarget = cr_schedule_http(itworks)
)
# }
# NOT RUN {
cr_project_set("my-project")
cr_bucket_set("my-bucket")
cloudbuild <- system.file("cloudbuild/cloudbuild.yaml",
package = "googleCloudRunner"
)
bb <- cr_build_make(cloudbuild)
# }
# NOT RUN {
# create a pubsub topic either in Google Console webUI or library(googlePubSubR)
library(googlePubsubR)
pubsub_auth()
topics_create("test-topic")
# }
# NOT RUN {
# create build trigger that will watch for messages to your created topic
pubsub_trigger <- cr_buildtrigger_pubsub("test-topic")
pubsub_trigger
# }
# NOT RUN {
# create the build trigger with in-line build
cr_buildtrigger(bb, name = "pubsub-triggered", trigger = pubsub_trigger)
# create scheduler that calls the pub/sub topic
cr_schedule("cloud-build-pubsub",
"15 5 * * *",
pubsubTarget = cr_schedule_pubsub("test-topic")
)
# }
# NOT RUN {
# builds can be also parametrised to respond to parameters within your pubsub topic
# this cloudbuild echos back the value sent in 'var1'
cloudbuild <- system.file("cloudbuild/cloudbuild_substitutions.yml",
package = "googleCloudRunner"
)
the_build <- cr_build_make(cloudbuild)
# var1 is sent via Pubsub to the buildtrigger
message <- list(var1 = "hello mum")
send_me <- jsonlite::base64_enc(jsonlite::toJSON(message))
# create build trigger that will work from pub/subscription
pubsub_trigger <- cr_buildtrigger_pubsub("test-topic")
# }
# NOT RUN {
cr_buildtrigger(the_build, name = "pubsub-triggered-subs", trigger = pubsub_trigger)
# create scheduler that calls the pub/sub topic with a parameter
cr_schedule("cloud-build-pubsub",
"15 5 * * *",
pubsubTarget = cr_schedule_pubsub("test-topic",
data = send_me
)
)
# }
# NOT RUN {
# }
# NOT RUN {
cr_project_set("my-project")
cr_region_set("europe-west1")
cr_schedule("test",
"* * * * *",
httpTarget = HttpTarget(uri="https://code.markedmondson.me"))
# schedule a cloud build (no source)
build1 <- cr_build_make("cloudbuild.yaml")
cr_schedule("cloud-build-test", "15 5 * * *",
httpTarget = cr_schedule_http(build1))
# schedule a cloud build with code source from GCS bucket
my_gcs_source <- cr_build_upload_gcs("my_folder", bucket = cr_get_bucket())
build <- cr_build_make("cloudbuild.yaml", source = my_gcs_source)
cr_schedule("cloud-build-test2", "15 5 * * *",
httpTarget = cr_schedule_http(build))
# update a schedule with the same name - only supply what you want to change
cr_schedule("cloud-build-test2", "12 6 * * *", overwrite=TRUE)
# By default will use the timezone as specified by Sys.timezone() - change
# this by supplying it directly
cr_schedule("timzone-utc", "12 2 * * *", timeZone = "UTC")
# schedule private Cloud Run app
# for authenticated Cloud Run apps - create with allowUnauthenticated=FALSE
cr_deploy_run("my-app", allowUnauthenticated = TRUE)
# deploying via R will help create a service email called my-app-invoker
cr_run_email("my-app")
#> "my-app-invoker@your-project.iam.gserviceaccount.com"
# schedule the endpoint
my_app <- cr_run_get("my-app")
endpoint <- paste0(my_app$status$url, "/fetch_stuff")
app_sched <- cr_run_schedule_http(endpoint, http_method = "GET",
email = cr_run_email("my-app"))
cr_schedule("my-app-scheduled-1", schedule = "16 4 * * *",
httpTarget = app_sched)
# creating build triggers that respond to pubsub events
\dontrun{
# create a pubsub topic either in webUI or via library(googlePubSubR)
library(googlePubsubR)
pubsub_auth()
topics_create("test-topic")
}
# create build trigger that will work from pub/subscription
pubsub_trigger <- cr_buildtrigger_pubsub("test-topic")
pubsub_trigger
\dontrun{
# create the build trigger with in-line build
cr_buildtrigger(bb, name = "pubsub-triggered", trigger = pubsub_trigger)
# create scheduler that calls the pub/sub topic
cr_schedule("cloud-build-pubsub",
"15 5 * * *",
pubsubTarget = cr_schedule_pubsub("test-topic"))
}
# }
Run the code above in your browser using DataLab