Skip to content

Instantly share code, notes, and snippets.

@ptone
Created March 2, 2019 13:30
Show Gist options
  • Save ptone/3c626b8a82d88545f88b7ed195d9b954 to your computer and use it in GitHub Desktop.
Save ptone/3c626b8a82d88545f88b7ed195d9b954 to your computer and use it in GitHub Desktop.
# Create pubsub topics for cron regular tasks
gcloud pubsub topics create cron-minute
gcloud pubsub topics create cron-hour
gcloud pubsub topics create cron-day
# Create minute, hour, daily heartbeat events
gcloud alpha scheduler jobs create pubsub minute-task --topic cron-minute --schedule="* * * * *" --message-body="OK"
gcloud alpha scheduler jobs create pubsub hour-task --topic cron-hour --schedule="0 * * * *" --message-body="OK"
gcloud alpha scheduler jobs create pubsub day-task --topic cron-day --schedule="0 2 * * *" --message-body="OK"
# For each consumer of these regular events, create their own subscription "foo"
# by limiting the retention time, you will never accumulate too many stale messages
# use this with https://cloud.google.com/functions/docs/calling/pubsub
# use the publish date in event context to ignore and ack older messages
gcloud pubsub subscriptions create minute-tasks-foo --topic cron-minute --message-retention-duration=10m
gcloud pubsub subscriptions create hour-tasks-foo --topic cron-hour --message-retention-duration=8h
gcloud pubsub subscriptions create daily-tasks-foo --topic cron-day --message-retention-duration=5d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment