Hello,
We aim to use a scheduled trigger to execute a function on a daily basis. For testing purposes, we have set the scheduled trigger interval to 1 hour. The function “startImport” executes hourly, which is working as expected. However, after reviewing the logs, we are finding them confusing.
Code:
import { startImport, getScheduledImports } from './configuration-resolver';
export async function dailyScheduler() {
console.log("starting daily scheduler")
try {
// Retrieve the list of imports to process
const importList = await getScheduledImports();
console.log(importList)
if (importList) {
for (const importItem of importList) {
// Start the import for each item
console.log(`Starting daily scheduled import for ${importItem.importId}`)
await startImport(importItem);
}
} else {
console.log('No imports to process today.');
}
} catch (error) {
console.error('Error in daily scheduler:', error);
}
}
Logs
Info 2024-09-17 00:11:25.545 starting daily scheduler
Info 2024-09-17 00:11:25.578 starting daily scheduler
Info 2024-09-17 00:11:25.746 []
Info 2024-09-17 00:11:25.794 [ { importId: 'PLACEHOLDER_IMPORT_ID', schemaId: '2', type: 'jiraServiceManagement:assetsImportType', workspaceId: 'PLACEHOLDER_WORKSPACE_ID' } ]
Info 2024-09-17 00:11:25.795 Starting daily scheduled import for PLACEHOLDER_IMPORT_ID
Info 2024-09-17 00:56:31.594 starting daily scheduler
Info 2024-09-17 00:56:31.812 []
Info 2024-09-17 01:11:25.774 starting daily scheduler
Info 2024-09-17 01:11:25.786 starting daily scheduler
Info 2024-09-17 01:11:25.989 [ { importId: 'PLACEHOLDER_IMPORT_ID', schemaId: '2', type: 'jiraServiceManagement:assetsImportType', workspaceId: 'PLACEHOLDER_WORKSPACE_ID' } ]
Info 2024-09-17 01:11:25.990 Starting daily scheduled import for PLACEHOLDER_IMPORT_ID
Info 2024-09-17 01:11:26.008 []
Info 2024-09-17 01:56:25.607 starting daily scheduler
Info 2024-09-17 01:56:25.799 []
Info 2024-09-17 02:11:25.911 starting daily scheduler
Info 2024-09-17 02:11:26.009 starting daily scheduler
Info 2024-09-17 02:11:26.131 []
Info 2024-09-17 02:11:26.289 [ { importId: 'PLACEHOLDER_IMPORT_ID', schemaId: '2', type: 'jiraServiceManagement:assetsImportType', workspaceId: 'PLACEHOLDER_WORKSPACE_ID' } ]
Info 2024-09-17 02:11:26.290 Starting daily scheduled import for PLACEHOLDER_IMPORT_ID
Info 2024-09-17 02:56:25.694 starting daily scheduler
Info 2024-09-17 02:56:25.915 []
Info 2024-09-17 03:11:25.626 starting daily scheduler
Info 2024-09-17 03:11:25.697 starting daily scheduler
Info 2024-09-17 03:11:25.839 [ { importId: 'PLACEHOLDER_IMPORT_ID', schemaId: '2', type: 'jiraServiceManagement:assetsImportType', workspaceId: 'PLACEHOLDER_WORKSPACE_ID' } ]
Info 2024-09-17 03:11:25.840 Starting daily scheduled import for PLACEHOLDER_IMPORT_ID
Info 2024-09-17 03:11:25.898 []
Info 2024-09-17 03:56:25.657 starting daily scheduler
Info 2024-09-17 03:56:25.871 []
Info 2024-09-17 04:11:25.674 starting daily scheduler
Info 2024-09-17 04:11:25.683 starting daily scheduler
Info 2024-09-17 04:11:25.874 [ { importId: 'PLACEHOLDER_IMPORT_ID', schemaId: '2', type: 'jiraServiceManagement:assetsImportType', workspaceId: 'PLACEHOLDER_WORKSPACE_ID' } ]
Info 2024-09-17 04:11:25.875 Starting daily scheduled import for PLACEHOLDER_IMPORT_ID
Info 2024-09-17 04:11:25.899 []
Info 2024-09-17 04:56:25.713 starting daily scheduler
Info 2024-09-17 04:56:25.932 []
Info 2024-09-17 05:11:25.844 starting daily scheduler
Info 2024-09-17 05:11:25.868 starting daily scheduler
Info 2024-09-17 05:11:26.064 [ { importId: 'PLACEHOLDER_IMPORT_ID', schemaId: '2', type: 'jiraServiceManagement:assetsImportType', workspaceId: 'PLACEHOLDER_WORKSPACE_ID' } ]
Info 2024-09-17 05:11:26.065 Starting daily scheduled import for PLACEHOLDER_IMPORT_ID
Info 2024-09-17 05:11:26.107 []
Info 2024-09-17 05:56:25.665 starting daily scheduler
Info 2024-09-17 05:56:25.863 []
From the logs, it seems that, for some reason, the function is executing multiple times per hour. Additionally, the array is sometimes empty and sometimes contains a value. The array is retrieved using storage.get()
and is not being modified in any other way, so I would expect it to contain a value every time. Could you explain why the scheduler appears to trigger multiple times per hour and why the array value from storage is inconsistent?
Thanks!