Bineroo 1.3: one Day, one Grid

What’s new in v1.3?

How does it work in detail?

  • Cloud Firestore
  • Cloud Functions
  • Cloud Messaging
Workflow “Getting the daily grid”
  • functions.region() gives you the possibility to change the region where your cloud function will be hosted. By default it is your project default region.
  • https.onRequest clearly shows that the cloud function is triggered on a HTTPs request. This is very convenient as you can test it directly from your browser. WARNING: don’t forget to protect access with IAM if you are exposing sensitive information (not the case here)
  • I found out that the JSON response must return information inside a data object. I am not sure it is absolutely mandatory. But as far as I remember it was not working well on the device side without it. To be clarified.
  • pubsub.schedule(‘0 8 * * *’) lets you define the periodicity of the function execution. Here it is defined as a classic Unix Crontab format but you can also use AppEngine syntax (ex: ‘every 5 minutes’). You can also note that scheduling a cloud function is making use of PubSub (real-time messaging platform of GCP). Indeed, once your function is deployed, you can see in the GCP console that a PubSub topic and subscription have been automatically created. In addition, a Cloud Scheduler job has also been automatically created. This job will run on the period cycle you set when building your scheduled cloud function. On every run, it will basically just send a message on the PubSub topic. The subscription will catch the message and trigger the cloud function.
  • timeZone(‘Europe/Paris’) indicates the time zone of the scheduler. In this case, the scheduler is running every day at 8 am Paris time.
  • Important to use Firestore datatypes to insert elements in the collection. Here the field generated_at is of type admin.firestore.Timestamp
Application states (from official documentation)
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if false; //deny all access. Cloud functions run under administrative privileges
}
}
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store