在缩放应用程序上的Openshift cron

时间:2016-07-09 22:06:40

标签: cron openshift

我有一个openhift应用程序,它运行一个cron盒式磁带。我最近改变它成为一个缩放的应用程序只是意识到cron将触发应用程序的所有缩放版本以及。这非常糟糕地打乱了我的数据库。

有没有简单的方法让cron任务只触发一次?尝试谷歌搜索,但遗憾地找不到答案..

1 个答案:

答案 0 :(得分:0)

Found a somewhat decent answer for this myself and posting it here incase someone else has the same problem. I'm currently using 2 gears for my application so I decided to check the environment variables and decide if the gear is allowed to run the cron job:

if(process.env.USER != "XXX"){
    console.log("STOP:"+process.env.USER);
    return;
}

This way the cron should only fire on the main gear.

The environment variable can be found by accessing your application with SSH and running the env command at the shell prompt.