TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: How do you monitor your background jobs?

1 点作者 kostarelo大约 5 年前
When you have many background jobs, that take either a few seconds or lots of minutes&#x2F;hours, how do you monitor them?<p>How do you know when they started and when they finished, their outcome, etc. Do others, non-tenchical folks, need access to that or is it just the developers?

1 comment

simonblack大约 5 年前
Most background jobs are run by cron.<p>Cron has the capability to set environment variables. The scripts&#x2F;programs can check those variables and then have the ability to adjust the type and quantity of logging according to whether they are run as cron jobs or from the command-line.<p>The logging of these jobs goes to a specific log file which is rotated daily. The daily logs are kept for 10 days before being discarded.<p>For instance this is a cron entry. Note the logfile argument as $1.<p><pre><code> # update BAK_MONTHLY on 2nd of the month only 24 09 2 * * &#x2F;home&#x2F;jvs&#x2F;binscripts&#x2F;rsync.bak.monthly.xpz &#x2F;var&#x2F;log&#x2F;cronlog_jvs </code></pre> This is cron setting variables in the crontab file<p><pre><code> # DO NOT EDIT THIS FILE - edit the master and reinstall. # tell cronjobs that they are running under cron CRONJOB=CRONJOB # specify the logfile for cronjobs output LOGFILE=&#x2F;var&#x2F;log&#x2F;cronlog_jvs # expand the path PATH=&#x2F;usr&#x2F;sbin:&#x2F;sbin:&#x2F;usr&#x2F;local&#x2F;sbin:&#x2F;usr&#x2F;bin:&#x2F;bin:&#x2F;usr&#x2F;local&#x2F;bin:&#x2F;home&#x2F;jvs&#x2F;binscripts # # m h dom mon dow command </code></pre> and this is a cronjob template<p><pre><code> #!&#x2F;bin&#x2F;bash #jvs script # # DATE WRITTEN ...... # # This crontab item does ........ # #Set variables TARGET= NOW=$(date +%y%m%d) DAY=$(date +%d) LOGFILE=&quot;&#x2F;tmp&#x2F;${HOSTNAME}.crontab-item.log&quot; if [ &quot;$1&quot; != &quot;&quot; ]; then LOGFILE=&quot;$1&quot; fi touch &quot;$LOGFILE&quot; chmod 666 &quot;$LOGFILE&quot; echo -e &quot;#######################################################\n &quot; &gt;&gt;&quot;$LOGFILE&quot; &#x2F;bin&#x2F;date +&quot;%F %H%M&quot; &gt;&gt;&quot;$LOGFILE&quot; 2&gt;&amp;1 echo &quot;$0&quot; &gt;&gt;&quot;$LOGFILE&quot; ### *************************************************** ### ******* Guts of crontab item goes here ******** ### *************************************************** # Say when this item completed echo -e &quot;\n$0 Completed at $(date)&quot; &gt;&gt;&quot;$LOGFILE&quot;</code></pre>