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:

https://firebase.googleblog.com/2017/03/how-to-schedule-cron-jobs-with-cloud.html

Start with prerequisites: Ensure these are available locally.

Clone the repository to a desired folder

git clone https://github.com/firebase/functions-cron

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 https://pypi.python.org/simple/google-api-python-client/: 
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 auth login
 
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>.appspot.com]


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

/functions-cron/functions

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>



Comments

Popular posts from this blog

ENOENT: no such file or directory, rename : node_modules/async

react-quill Integrate quill-image-resize-module

Custom Email template for Laravel Password Reset