[SOLVED] Await in Cloud Jobs and Cloud Functions

hi,
still fighting with some code on the cloudside :slight_smile:

currently i am trying to get a job done, i got already some tests working, so i know the job in general would work. but as soon as i add “await” to anything… does not matter what, i get “unexpexted identifier” and my joblog is saying (in this case for example) "query.find is not a function or is not iterable)

Moralis.Cloud.job("historicalprices", (request) =>  {
    const logger = Moralis.Cloud.getLogger();
    const { params, headers, log, message } = request;
    message("I just started");
    const BscTransfers = Moralis.Object.extend("BscTokenTransfers");
    const query = new Moralis.Query(BscTransfers);
    
    query.equalTo("historical", true);
    query.equalTo("usdval", undefined);
    let transfers = await query.find({useMasterKey:true});

    for (transfer of transfers) {
        logger.info("From: "+transfer.get("from_address"));
        logger.info("Token: "+transfer.get("token_address"));
        logger.info("Block: "+transfer.get("block_number"));
        
      }

  });

perhaps i am just too tired after days of coding, but i dont see the error :slight_smile: so … is there a problem with await int cloud jobs?

greetings

you have to define that function with async:

Moralis.Cloud.job("historicalprices", async (request) => {

1 Like

my gosh i am stupid as hell rofl … definitly time to take a break some hours haha…

thank you and sorry for wasting your time ^^

2 Likes