Reputation: 187
When I deployed my Cloud Functions previously I could see the logs and everything in the logs explorer. However, there were some errors and upon some research, I found that in order to get my queue in the functions I have to create it Cloud Functions SDK. So I downloaded it. The installation requires Python so I downloaded it as well. I created my queue Id successfully and I placed it in my functions.
However, after all these, when I deploy a function, I don't see my logs in the logs explorer anymore. The terminal tells me the deploy complete. I see the deployed functions in the Firebase Console, but when I click on view logs, I don't see the deployed logs.
Even when I go to "Recent" on my log explorer, I see the functions there. But when I click on it I don't see any log.
....................................................................
I use firebase deploy --only functions:FUNCTIONS_NAME
to deploy my functions.
I'm using JavaScript
My code
const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp();
const database = admin.firestore();
exports.taskCallback = functions.https
.onRequest(async (req, res) => {
const {UID} = req.body;
const docRef = database.collection("ADSGHANA").doc(UID);
const doc = await docRef.get();
if (!doc.exists) {
console.log(`Document with UID ${UID} does not exist.`);
res.status(404).send("Document not found.");
return;
}
const {TimestampDeparture, PostStatus} = doc.data();
const now = admin.firestore.Timestamp.now();
if (now == TimestampDeparture && PostStatus !== "Cancelled") {
await docRef.update({PostStatus: "Started"});
console.log(`Post with UID ${UID} has been started.`);
res.status(200).send("Post started successfully.");
} else {
console.log(`Post with UID ${UID} is not ready to start.`);
res.status(200).send("Post not ready to start yet.");
}
});
exports.scheduledTask = functions.firestore.document("ADSGHANA/{UID}")
.onCreate(async (snapshot, context) => {
const data = snapshot.data();
const {UID, TimestampDeparture} = data;
const now = admin.firestore.Timestamp.now();
if (now == TimestampDeparture) {
console.log(`Post with UID ${UID} should have already started.`);
return null;
}
const project = JSON.parse(process.env.FIREBASE_CONFIG).projectId;
const location = "us-central1";
const queue = "scheduleAds";
const task = {
httpRequest: {
httpMethod: "POST",
url: `https://${location}/${project}.cloudfunctions.net/taskCallback?UID=${UID}`,
body: Buffer.from(JSON.stringify({UID})).toString("base64"),
headers: {
"Content-Type": "application/json",
},
},
scheduleTime: TimestampDeparture,
};
const {CloudTasksClient} = require("@google-cloud/tasks");
const client = new CloudTasksClient();
const parent = client.queuePath(project, location, queue);
const [response] = await client.createTask({parent, task});
console.log(`Created task ${response.name}`);
return null;
});
Upvotes: 0
Views: 105