Anybody ever have scripts just hang. A scheduled s...
# suitescript
m
Anybody ever have scripts just hang. A scheduled script started hanging when it's finished.
Copy code
// loop through the JSON files from Suitelet
file_results_mapped.some(file_result => {

    // parse settings from a string into a javascript object
    const file_updates = JSON.parse(settings_file.getContents());

    // loop through the selected_transactions 
    file_updates.selected_transactions.some(transaction => {

        // ... process transaction updates 

        if (runtime.getCurrentScript().getRemainingUsage() < 500) {
            governance_triggered = true;
            log.audit({
                title: 'STOPPING_DUE_TO_GOVERNANCE',
                details: {
                    getRemainingUsage: runtime.getCurrentScript().getRemainingUsage()
                }
            });
            return true; // breaks internal loop
        }
    });

    // ... send email update about processed transactions

    if (governance_triggered === true && file_updates.selected_transactions.length > 0) {
        const file_object = file.create({
            name: settings_file.name,
            fileType: file.Type.JSON,
            folder: settings_file.folder,
            contents: JSON.stringify(file_updates),
            encoding: file.Encoding.UTF8
        });

        file_object.save();
        log.audit({
            title: "FILE_UPDATED",
            details: {
                name: settings_file.name,
            }
        });
    } else {
        // delete the file so it doesn't get processed again
        file.delete({
            id: file_result.id
        });

        log.audit({
            title: "FILE_DELETED",
            details: {
                id: file_result.id      
            }
        });
    }
    return governance_triggered;
});
I can see it log STOPPING_DUE_TO_GOVERNANCE and then FILE_UPDATED. The last line
return governance_triggered;
should break from the
.some
loop and end the script.
I know the best solution would be use a Map/Reduce script. But until I have time to rewrite I was hoping somebody ran into the issue before.
s
if you've hit the governance limit, wouldn't the file.delete() cause the failure since it uses governance as well?
m
Governance is low, but not depleted. If it was governance it should throw and error and quite. Instead the script just continues to run for about 20 mins after logging that it's quitting due to governance.