Cloud Function keeping an eye on tracks played in Raadio Tallinn and storing them in Cloud Firestore.
I enjoy the music of Raadio Tallinn and created this function for personal use. The data from Firestore can be used in many ways, for example to add new tracks to a playlist in Spotify.
Note about the lazy initialization
I tried lazy initialization mostly for trying it out, although it seems to perform similarly without laziness as well. 🚀 Next time around I would not do the lazy init. again if not absolutely necessary. I prefer simple and readable code over crazy-optimized code in most of the cases.
This deploys the function that is ready for accepting messages from the Cloud PubSub topic playlists-by-tallinn
. Set up a Cloud Scheduler cron-job for triggering the function periodically.
Songs are stored in Cloud Firestore collection playlists-by-tallinn
.
gcloud functions deploy PlaylistsByTallinn \
--service-account your-service-account@gcpproject.iam.gserviceaccount.com
--trigger-topic playlists-by-tallinn \
--region europe-west1 \
--runtime go111 \
--memory 128MB \
--timeout 2s
These are handled by Cloud Functions, only needed to specify locally.
export GCP_PROJECT=your-gcp-project-id
export GOOGLE_APPLICATION_CREDENTIALS=full-path-to-service-account-credentials.json
More info: https://cloud.google.com/docs/authentication/getting-started
In the app directory, execute:
make run