I have a job setup that is scheduled and takes a json object as an input
{“interval”: 5}
whenever I manually start that scheduled job, everything is fine and job succeeds. If the job is triggered by the schedule, the input params are undefined according to the log. Is this a bug?
Moralis.Cloud.job("UpdateEthBalances", async request => {
const { params, headers, log, message } = request;
let interval;
if (params["input"].interval) {
interval = params["input"].interval;
} else {
interval = 5;
}
logger.info("--------------------------------------------------------");
logger.info("--------------------------------------------------------");
logger.info("JOB UpdateEthBalances started");
logger.info("Params " + JSON.stringify(request.params["input"]));
const addressSyncStatus = Moralis.Object.extend("_AddressSyncStatus");
const query = new Moralis.Query(addressSyncStatus);
const now = new Date();
const then = new Date(now.getTime() - interval * 60000);
query.lessThan("updatedAt", then);
const result = await query.find();
logger.info("found " + result.length + " addresses to update");
for (const r of result) {
try {
const balance = await Moralis.Web3API.account.getNativeBalance({
address: r.get("address")
});
const ethBalance = await Moralis.Cloud.units({
method: "fromWei",
value: balance["balance"]
});
logger.info(
"trying to update balance for " +
r.get("address") +
" of: " +
ethBalance +
" ETH"
);
r.set("value", Number(ethBalance));
r.save(null, { useMasterKey: true });
} catch (error) {
logger.info("JOB updateEthBalances ");
}
}
logger.info("--------------------------------------------------------");
logger.info("--------------------------------------------------------");
});
The jobs marked with “M” are manually started jobs under the “scheduled jobs” tab. The one that failed is the one automatically starting based on the schedule I set.