用于每小时发送状态电子邮件的任何现有项目/软件

发布于 2024-12-27 02:53:12 字数 467 浏览 1 评论 0原文

检查系统状态并通知用户的经典需求。具体来说,我将每隔 x 时间访问数据库,获取一些数据,然后根据结果发送电子邮件通知。哎呀,该服务甚至可能不会发送电子邮件,而是在数据库中创建通知记录。

似乎通过 IOC 和配置,可以有一个通用的 Windows 服务以简单的方式管理所有这些以及指标和管理。

过去我通过以下方式完成电子邮件通知: 1) 将脚本作为 cron(Windows 上的 at)作业运行 2) 将自定义可执行文件作为 cron/at 作业运行 3)使用SQLServer的DatabaseMail之类的东西。 4) 始终运行监视事物的自定义 NT 服务。

有没有开源项目可以管理这个?这是我在各种平台上编写过很多次的代码类型,但现在不想花几天时间来做。

到目前为止我唯一发现的是 Quartz.Net

谢谢

Classic requirement of checking system state and notifying users. Specifically, I'll be hitting the database every x-amount of time, getting some data, then sending out email notifications based on the results. Heck, this service might not even send out an email, but create a notification record in the database.

Seems like with IOC and configuration there could be a generic windows service that manages all this, along with metrics and management, in a simple manner.

In the past I've done email notifications by:
1) Running scripts as cron (at on Windows) jobs
2) running custom executables as cron/at jobs
3) using something like SQLServer's DatabaseMail.
4) Custom NT Services that run all the time monitoring things.

Is there any open source projects that manages this? It's the type of code I've written many, many times in various platforms, but don't want to spend the few days doing it now.

The only thing I found so far was Quartz.Net

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

何时共饮酒 2025-01-03 02:53:12

我只是创建一个 Windows 服务并使用响应式扩展来安排任务。如果您不需要 cron 提供的灵活性,那么这很好用。这是一个抽象的每小时任务运行程序。 (使用 log4net)

public abstract class HourlyTask : IWantToRunAtStartup
{
    protected readonly ILog Log = LogManager.GetLogger(typeof (HourlyTask).FullName);
    private IDisposable _Subscription;

    private void ExecuteWithLog()
    {
        Log.Debug("Triggering " + GetType());
        try
        {
            Execute();
        }
        catch (Exception exception)
        {
            Log.Error("Hourly execution failed", exception);
        }
    }

    public abstract void Execute();

    public void Run()
    {
        _Subscription = Observable
            .Interval(TimeSpan.FromMinutes(1))
            .Select(x => DateTime.Now.Hour)
            .DistinctUntilChanged()
            .Subscribe(i => ExecuteWithLog());
    }

    public void Stop()
    {
        if (_Subscription == null)
        {
            return;
        }
        _Subscription.Dispose();
    }
}

然后在启动方法中,您可以解析所有 IWantToRunAtStartup 实例并对其调用 Run()

I just create a Windows service and use the Reactive Extensions to schedule tasks. If you don't need as much flexibility as cron offers, this works fine. Here's an abstract hourly task runner. (uses log4net)

public abstract class HourlyTask : IWantToRunAtStartup
{
    protected readonly ILog Log = LogManager.GetLogger(typeof (HourlyTask).FullName);
    private IDisposable _Subscription;

    private void ExecuteWithLog()
    {
        Log.Debug("Triggering " + GetType());
        try
        {
            Execute();
        }
        catch (Exception exception)
        {
            Log.Error("Hourly execution failed", exception);
        }
    }

    public abstract void Execute();

    public void Run()
    {
        _Subscription = Observable
            .Interval(TimeSpan.FromMinutes(1))
            .Select(x => DateTime.Now.Hour)
            .DistinctUntilChanged()
            .Subscribe(i => ExecuteWithLog());
    }

    public void Stop()
    {
        if (_Subscription == null)
        {
            return;
        }
        _Subscription.Dispose();
    }
}

Then in your start up method you can just resolve all IWantToRunAtStartup instances and call Run() on them.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文