Skip to content
This repository has been archived by the owner on Dec 14, 2022. It is now read-only.

Latest commit

 

History

History
105 lines (68 loc) · 3.33 KB

README.md

File metadata and controls

105 lines (68 loc) · 3.33 KB

⚠️ THIS REPO HAS BEEN ARCHIVED AND IS NO LONGER MAINTAINED. ⚠️

Cloud Tasks Pizza Map

Google Maps of Earth with 16k pins

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:

  1. Creates a Cloud Tasks Queue
  2. Creates ~10,000 Cloud Tasks with different names of cities
  3. Each Cloud Task triggers a Cloud Function. This Function does the following:
    1. Looks up the best pizza restaurant in that city accoring to the Google Maps Places API
    2. Stores the restaurant data in Firestore

An application architecture diagram of the Cloud Tasks with an HTTP target of a Cloud Function. The Cloud Function uses the Google Maps Nearby/Places APIs for map data and Firestore to store location data.

Setup

This sample uses many APIs and a Firestore database that must be enable prior to running the application.

Enable all APIs

The following APIs are used in this app:

  • Cloud Tasks API
  • Maps Places API
  • Maps Geocoding API
  • Firestore API

Enable these APIs.

Create a Firestore database

Create a Firestore database with these configurations:

  • Mode: Test mode
  • Collection: tasks-pizza.

Create an API Key

Create a Google Maps API key. Create an .env file with a Google Maps API key:

KEY=AIeSyDh7ggKmvLzFAeq_ICGkO8ryvEMm3Nrde-z

Run the Functions Framework

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.

Deploy to Google Cloud

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 to Google Cloud Function

Deploy your function on Google Cloud Functions on runtime Node 10:

npm run functions

Deploy to Google Cloud Run

You can also deploy this application to Cloud Run by first building the container, then deploying:

npm run cloudrun

GIF

Here is a GIF of the applicaiton working at different Google Map zoom levels A Google Map with thousands of pins at different zoom levels