Q:

Firebase admin SDK not working on Cloud Scheduler (PubSub)

I have an app and I want to update weather details on every 5 minutes.  I build a PubSub function on Google cloud function to get weather details from weatherstack.com website and then I'm trying to save the result on FireStore using Admin SDK. 
The weather API working perfectly but the function that writes the data to FireStore not triggered. 
My code:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const requestApi = require('request');

admin.initializeApp();

exports. WeatherPubSub = (event, context) => {

    requestApi({
        url: 'http://api.weatherstack.com/current?access_key=XXXXXXXXXXXXXXXXXXXX&query=XXXXX',
        method: "POST"
    }, (error, response, body) => {
        //console.log(JSON.parse(body));
        if (error) {
            console.log('error:', error); // Print the error if one occurred
        } else {
            console.log("=> "+ response.statusCode);
            //Call firestore to update weather data
            return admin.firestore().collection('settings').doc('weather').update({
                temperature: body.current['temperature'],
                humidity: body.current['humidity'],
                weather_descriptions: body.current['weather_descriptions'][0]
            }).then(function() {
                console.log('Done!'); 
            });
        }

    });

  //return null;
};

package.json
{
  "name": "functions",
  "version": "0.0.2",
  "description": "Cloud Functions for Firebase",
  "scripts": {
    "serve": "firebase serve --only functions",
    "shell": "firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "8"
  },
  "dependencies": {
    "@google-cloud/pubsub": "^1.5.0",
    "firebase-admin": "^8.9.2",
    "firebase-functions": "^3.3.0",
    "request": "^2.88.2"
  },
  "devDependencies": {
    "firebase-functions-test": "^0.1.6"
  },
  "private": true
}

A:

You must return a promise that resolves when all the asynchronous work in your Cloud Function is complete (i.e. call to the weatherstack API and Firestore update() method).  
This is explained in the official Firebase video series here.  In particular watch the three videos titled "Learn JavaScript Promises" (Parts 2 & 3 especially focus on background triggered Cloud Functions, but it really worth watching Part 1 before). 

The request library you are using supports callback interfaces natively but does not return a promise. 
You can use the request-promise library and the rp() method which "returns a regular Promises/A+ compliant promise" and then adapt your code as follows:
 //.....
 var options = {
        method: 'POST',
        uri: 'http://api.weatherstack.com/current?access_key=XXXXXXXXXXXXXXXXXXXX&query=XXXXX'
 };

return rp(options)
.then(body => {
       return admin.firestore().collection('settings').doc('weather').update({
                temperature: body.current['temperature'],
                humidity: body.current['humidity'],
                weather_descriptions: body.current['weather_descriptions'][0]
            }
})
.catch(err => {
    console.log(err);
    return null;  
});
 //.....

Also, you should double-check that the way you declare you cloud Function (exports. WeatherPubSub = (event, context) => {...}) is correct.  It does not seem to be the case, see the doc for more details.