Reputation: 2346
I'm using GCP and serverless framework. And wish to create a scheduled function. For AWS lambdas i can add to the .yml:
functions:
crawl:
handler: crawl
events:
- schedule: rate(2 hours)
- schedule: cron(0 12 * * ? *)
Seems like no such option for GCP - correct me if i'm wrong. What is the simplest way to implement it in CGP?
Upvotes: 1
Views: 793
Reputation: 2346
Thanks for all the responses, this is the complete solution as i see it including yaml:
In serverless.yml:
functions:
oneMinute:
handler: oneMinuteHandler
events:
- event:
eventType: providers/cloud.pubsub/eventTypes/topic.publish
resource: 'projects/${self:provider.project, ""}/topics/one-minute-topic'
This will also create the topic when running serverless deploy
Now all that is left is to create a scheduler:
GCP -> Cloud Scheduler -> Create Job
Target: Pub/Sub
Topic: one-minute-topic
Upvotes: 1
Reputation: 81356
Google Cloud's recommended solution for scheduling services such as Cloud Functions is Cloud Scheduler.
Cloud Scheduler is a fully managed service with enterprise-reliability and supports the popular Unix/Linux cron format.
Cloud Scheduler product information
Google Cloud Functions Tutorial: Using the Cloud Scheduler to trigger your functions
Upvotes: 0