简体   繁体   English

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

[英]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.我正在尝试编写一个 cron 作业,该作业从 SFTP 服务器获取 excel 文件并将数据上传到 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.现在,假设由于某些凭据问题或需要从中提取文件的路径不存在导致 cronjob 出现错误,例如 sftp 连接失败,那么控件将进入下面的代码片段中的 catch 内部,而不是标记cron 作为错误,它在 kubernetes 上显示为已完成。

I have attached a basic sample code below of the cron job to get an idea about what I am trying to say.我在 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);
}

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 .您的catch块可以使用process.exit(1)throw Error

暂无
暂无

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

相关问题 使用for循环获取JavaScript错误,即使它正在工作 - Getting javascript error with a for loop even though it's working 出现错误“轴0的数据列不能为字符串类型”,即使我替换了网址 - Getting Error “Data column(s) for axis #0 cannot be of type string” even though im replacing URL 即使我的 json 有效,也会收到“错误:无效的 Geojson 对象” - getting "Error: Invalid Geojson Object" even though my json is valid 出现错误(ReferenceError: steamMSG is not defined),即使我给它赋值 - Getting an error (ReferenceError: steamMSG is not defined) even though I assign it a value 有没有办法在cron中立即启动一个作业,然后在执行完成后停止它? - Is there a way to start a job immediately in cron and then stop it after the execution is completed? Cron Job 执行多次,直到整分钟完成, - Cron Job executes multiple times till the entire minute is completed, 属性被标记为未定义,即使它在同一行上被完美使用? - property marked as undefined even though it is being used on the same line flawlessly? 即使我定义了一个字符串,我也收到了一个错误,即使我定义了一个字符串,我也收到了一个错误 - I'm getting an error even though I defined a string and I'm getting an error even though I defined a string 即使启用了通过JavaScript加载的图像,也会引发CORS错误 - Images loaded through JavaScript are throwing me CORS errors even though it's enabled '$ set'为空,即使不是 - '$set' is empty even though it's not
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM