Search code examples
netlifynetlify-cmsnetlify-function

Netlify Lambda function log hangs forever


lam

The Function Log seems has the spinning slash forever.

here is my code:

const {getSubscriptions, getResponse} = require('./utils/utils.js');

module.exports.handler = async function(event, context) {

    

    const allItems = await getSubscriptions();

    

    if (!allItems) {

        return getResponse(204, "");

    }

    console.log('showCache is called', allItems);

    const subscriptions = allItems.map(item => item.data);

    const result = JSON.stringify(subscriptions);

    console.log('-------------result----------', result);

     return getResponse(200, result);

}

const getSubscriptions = async () => {

  try {

    const response = await client.query(

      q.Paginate(q.Match(q.Ref("indexes/all_subs")))

    );

    console.log("---response---", response);

    const subsRefs = response.data;

    if (!subsRefs) {

      return null;

    }

    console.log(`${subsRefs.length} subscription found`);

    const getAllSubsQuery = subsRefs.map((ref) => q.Get(ref));

    const allSubscriptions = await client.query(getAllSubsQuery);

    console.log("---------getSubsFinal-------", allSubscriptions);

    return allSubscriptions;

  } catch (faunaDBError) {

    console.log("----getSubscriptions error----", faunaDBError);

    return null;

  }

};

const faunadb = require("faunadb");

const q = faunadb.query;

const client = new faunadb.Client({

  secret: process.env.FAUNADB_SERVER_SECRET,

});

const headers = {

  'Access-Control-Allow-Origin': '*',

  'Access-Control-Allow-Headers': 'Content-Type',

  'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE'

};

function getResponse(statusCode, body) {

  return {

    statusCode: statusCode,

    headers,

    body: body,

  };

}

I searched a while and found similar questions but they are caused by not waiting for async function. From my code, I think I have await everywhere it needs.


Solution

  • My understanding was once I opened a Function Log page, I would be able to see logs since the current deployment.

    But it seems that after I opened the Function Log page, I have to make at least one call to the api in order to see logs, which is not intuitive.

    Not sure whether this is the fix, but at least I start seeing logs now.