@每月cron工作不可靠 [英] @monthly cron job is not reliable

查看:78
本文介绍了@每月cron工作不可靠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的客户希望我们每个月创建一个报告。

Our customer wants us to create a report every month.

过去,我们使用@monthly cron作业来完成此任务。

In the past, we used a @monthly cron job for this task.

但这不可靠:


  1. 此刻服务器可能已关闭。 Cron不会重新运行这些作业

  2. 如果服务器已启动,则此刻数据库可能无法访问。

  3. 如果服务器已启动并且数据库已启动,可能存在无法访问的第三方系统

  4. 可能存在软件错误。

  1. The server could be down in this minute. Cron does not re-run those jobs
  2. If the server is up, the database could be unreachable in this moment.
  3. If the server is up and DB is up, there could be a third party system which is not reachable
  4. There could be a software bug.

该怎么做才能确保每月创建一次报告?

What can I do, to be sure that the report gets created monthly?

这是一个基于Django的网络应用程序

It is a Django based web application

推荐答案

您应该编写一些脚本来测试条件并执行所有必需的操作。

You should write some script that will test conditions and perform all required operations.

if is_work_finished_less_then_month_ago():
    return
else:
    try:
        generate_normal_report()
    except some_error as e:
        report_about_error(e)

然后每小时或每天运行一次。

Then run it every hour or day.

如果您担心太多的error_reports,请使用 report_about_error()方法执行相同的操作:检查上次发送报告的时间并执行如果发送太频繁,则不发送。

If you afraid of too many error_reports then do the same thing in report_about_error() method: check last time you sent report and do not send it if it's too often.

这篇关于@每月cron工作不可靠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆