簡體   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