[英]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.