简体   繁体   中英

Cron job is getting marked as completed instead of error on k8s, even though there are errors

I am trying to write a cron job which takes an excel file from SFTP server and upload the data on mongo DB.

Now, suppose there are errors in cronjob like sftp connection failure due to some credentials issue or path from where the file needs to be picked up from is not present, then the control is going inside catch in the below code snippet but instead of marking the cron as Error, it is showing as completed on kubernetes.

I have attached a basic sample code below of the cron job to get an idea about what I am trying to say.

exports.fsmOverallPerformanceData = async (req, res) => {
    let sftp = new Client;
    const fileName = "FSM_Performance_Data.xlsx"
    const remote = "/home/SI_MARCOM_TOPS/SI_JHDSFTP/SND/"
    const remotePath = remote + fileName
    const localePath = "./fsmperformance.csv";
    sftp.connect(config.sftpSetting, 'once').then(() => {
        sftp.fastGet(remotePath, localePath, {}).then(() => {

        }).catch((err) => {
            console.log(err, 'FSM Performance fastGet method error'); // this is getting printed
        })
    }).catch((err) => {
        console.log(err, 'SFTP Connect method error'); // this is getting printed
    });
    setTimeout(() => {
        process.exit();
    }, 300000);
}

Thanks in advance for any suggestions or help.

You must ensure that the process exits with a non-zero exit code. Your catch blocks could use a process.exit(1) and throw Error .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM