定时任务应该放在哪一层? [英] Which layer should scheduled task be put?

查看:64
本文介绍了定时任务应该放在哪一层?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用分层架构实现 DDD 应用程序.我有:

I'm trying to implement DDD application with layered architecture. I have:

  • 基础设施层 - 实现应用程序特定技术部分的层.
  • 领域层 - 包含领域模型的层.
  • 应用层 - 包含与领域模型交互的干扰的层.
  • 接口层 - 从外部接收事件的层.

经典的 3 层(+ 基础设施)架构非常清晰.但是我的应用程序不是很经典.在 UI 旁边,我有计划任务,应该定期运行.我想过把这样的任务放到接口层,因为这些任务实际上处理UI之类的事件.但是有一个问题,我无法决定应该在哪个层放置一个调度程序来为计划任务触发事件.

The classic 3 layer (+ infrastructure) architecture is quite clear. But my application isn't very classic. Beside UI I have scheduled task which should be ran periodically. I thought about putting such tasks into interfaces layer, because these task actually handle events like UI. But there is a problem, I can't make decision which layer I should put an scheduler which fire events for scheduled tasks.

我画了草图

调度器对象应该放在哪一层?或者可能是使用内部事件生成器设计应用程序的另一种方法.

Which layer should I put the scheduler object? Or may be where is another way to design application with internal event generator.

推荐答案

对我来说,调度器是任务执行器的宿主(就像你的 JSP 容器是你 UI 的宿主一样).我会将其建模为外部实体,并将其作为另一个基础设施项目实施.

To me, scheduler is a host for task executor (in the same way as your JSP container is a host for you UI). I would model it as an external entity and implement it as another infrastructure project.

这篇关于定时任务应该放在哪一层?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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