Schedule Task on Google Cloud (Firebase)

Major difficulty I faced as a backend-developer using stripe is the automated tasks running in the back-end based on time.For an example a batch process run in night or a small intended delay within a user process.

The use of javascript based delay functions cannot accept in enterprise level applications, due to high unreliability within them.
For example, all the delay functions might removed within sever restart.

During the search of solid solution, I found the google cloud cron jobs,  which overcome the issue without going out of google platform.

Thanks for the reference:

Start with prerequisites: Ensure these are available locally.

Clone the repository to a desired folder

git clone

Move to functions-cron folder from the command line enable gclould tool to use your project.
gcloud config set project <firebase-project-id>

 You can check the settings applied or not from the following command.

gcloud config list

Than you have to move to appengine folder which contain the pub/sub code in python to create a google task in google cloud.You can define these tasks in cron.yml file. It include the cron job description, URL, schedule and timezone.

cd appengine/

Then you have to install python dependencies.This part can create problem based on the pip version installed in your system.It can be pip or pip3.

 pip install -t lib -r requirements.txt
Using older version of pip , will lead to following issue.
Could not fetch URL 
There was a problem confirming the ssl certificate: 
[SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:590) - skipping
If you are using Mac OSX Sierra, fallow the link and do the necessary paths. 

pip3 install -t lib -r requirements.txt --upgrade 
If you are doing it for the first time , use the code an create app. 
gcloud app create 

gcloud app deploy app.yaml \cron.yaml
descriptor:      [/path/appengine/app.yaml]
source:          [/path/appengine]
target project:  [<project>]
target service:  [default]
target version:  [20180510t160023]
target url:      [https://<project>]

Configurations to update:

descriptor:      [/<path>/appengine/cron.yaml]
type:            [cron jobs]
target project:  [<project>]

Do you want to continue (Y/n)?
Now we have created with task trigger  

Then move to fire-base function side


Error: Error parsing triggers: Cannot find module 'firebase-functions'

 npm install

you might ask to install the firebase functions latest.
npm i --save firebase-functions@latest

however this might create integrity issues with other packages such as firebase-admin.

 firebase deploy --only functions --project <projectname>


Popular posts from this blog

Uplaod to Firebase Storage from Node Express REST

Firebase Cloud Functions TypeError: Cannot read property 'val' of undefined

Custom Email template for Laravel Password Reset