As featured on Medium: https://medium.com/p/db888675db71/
A sample application using Cloud Tasks and Google Maps to find the best pizza restaurants around the world.
The program works in the following way:
- Creates a Cloud Tasks Queue
- Creates ~10,000 Cloud Tasks with different names of cities
- Each Cloud Task triggers a Cloud Function. This Function does the following:
- Looks up the best pizza restaurant in that city accoring to the Google Maps Places API
- Stores the restaurant data in Firestore
This sample uses many APIs and a Firestore database that must be enable prior to running the application.
The following APIs are used in this app:
Cloud Tasks API
Maps Places API
Maps Geocoding API
Firestore API
Create a Firestore
database with these configurations:
- Mode:
Test mode
- Collection:
tasks-pizza
.
Create a Google Maps API key.
Create an .env
file with a Google Maps API key:
KEY=AIeSyDh7ggKmvLzFAeq_ICGkO8ryvEMm3Nrde-z
The Functions Framework enables you to run a Google Cloud Function locally on your computer. This is very useful for testing our code.
To test our server locally, follow these instructions using our KEY
from the previous step:
npm i
KEY=??? npm start
Observe the Functions Framework starts a server and logs information:
npx: installed 52 in 8.771s
Serving function...
Function: function
URL: http://localhost:8080/
Go to URL specified to view all routes for the application.
You have two options for deploying this application to Google Cloud:
- Cloud Functions
- Cloud Run
The gcloud
commands for deploying to each target are in the scripts.sh
file.
Deploy your function on Google Cloud Functions on runtime Node 10:
npm run functions
You can also deploy this application to Cloud Run by first building the container, then deploying:
npm run cloudrun
Here is a GIF of the applicaiton working at different Google Map zoom levels