繁体   English   中英

Cron 作业在 k8s 上被标记为已完成而不是错误,即使有错误

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

我正在尝试编写一个 cron 作业,该作业从 SFTP 服务器获取 excel 文件并将数据上传到 mongo DB。

现在,假设由于某些凭据问题或需要从中提取文件的路径不存在导致 cronjob 出现错误,例如 sftp 连接失败,那么控件将进入下面的代码片段中的 catch 内部,而不是标记cron 作为错误,它在 kubernetes 上显示为已完成。

我在 cron 作业下面附上了一个基本示例代码,以了解我想说什么。

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);
}

提前感谢您的任何建议或帮助。

您必须确保进程以非零退出代码退出。 您的catch块可以使用process.exit(1)throw Error

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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