hi team, I created a scheduled trigger
export async function scheduledTrigger(event) {
const key = 'count'; // Key to store the count
// Retrieve the existing count from storage
const existingCount = await storage.get(key);
// Calculate the new count (increment by 1)
const newCount = (existingCount || 0) + 1;
// Store the updated count back into storage
await storage.set(key, newCount);
console.log(`Count updated. New count: ${newCount}`);
}
in my index.js file and when I install the app in any of my accounts like
any of these accounts it creates a storage with that key
similarily I want to create a function
const data = async (key, newValue) => {
// Check if the key exists in storage
const existingValue = await storage.get(key);
if (existingValue) {
// Find the maximum key value in existingValue
const maxKey = existingValue.reduce((max, obj) => Math.max(max, obj.key), -1);
// Increment the max key value by one to generate a new key
const newKey = maxKey + 1;
// Update the key field of each item in newValue
newValue.forEach(item => item.key = newKey);
// Push the new data into existingValue
existingValue.push(...newValue);
// Update the storage with the modified existingValue
await storage.set(key, existingValue);
// console.log(`Updated data for key ${key}:`, existingValue);
return { key: key, data: existingValue };
} else {
// If the key doesn't exist, set the key field of each item in newValue to 0
newValue.forEach(item => item.key = 0);
// Set the key-value pair in storage
await storage.set(key, newValue);
//console.log(`Created new key-value pair for key ${key}:`, newValue);
return { key: key, data: newValue };
}
};
which updates the storage after an hour interval for all the accounts , how can I achieve it ?
for now I am invoking the data function from my App.js file but I want it to be scheduled to update each hour , please help