设计问题:您将如何设计一个定期的事件系统? [英] Design question: How would you design a recurring event system?

查看:129
本文介绍了设计问题:您将如何设计一个定期的事件系统?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您有责任建立一个支持重复事件的事件调度系统,您将如何做?何时删除重复事件时如何处理?如何看待未来的事件何时会发生?

If you were tasked to build an event scheduling system that supported recurring events, how would you do it? How do you handle when an recurring event is removed? How could you see when the future events will happen?

创建活动时,您可以选择每天重复(或每周,每年等)。

i.e. When creating an event, you could pick "repeating daily" (or weekly, yearly, etc).

我习惯了Ruby / Rails,但是您可以使用任何您想要表达设计的内容。

One design per response please. I'm used to Ruby/Rails, but use whatever you want to express the design.

我在面试中被问到这个问题,无法想出

I was asked this at an interview, and couldn't come up with a really good response that I liked.

注意:

Note: was already asked/answered here. But I was hoping to get some more practical details, as detailed below:


  • 如果有必要可以评论或以其他方式将数据添加到一个定期事件的一个实例,那么该如何工作?

  • <
  • 如何计算未来事件发生的时间?

推荐答案

我开始通过执行一些时间表达式作为由Martin Fowler概述。这意味着确定实际发生的预定项目的时间。这是一种非常优雅的做法。我最后得到的只是一篇文章的内容。

I started by implementing some temporal expression as outlined by Martin Fowler. This takes care of figuring out when a scheduled item should actually occur. It is a very elegant way of doing it. What I ended up with was just a build up on what is in the article.

下一个问题是弄清楚在世界上如何存储表达式。另一个问题是当您读出表达式时,如何适应不那么动态的用户界面?有人在谈论刚刚把表达式序列化成一个BLOB,但是很难走出表达式树来知道它是什么意思。

The next problem was figuring out how in the world to store the expressions. The other issue is when you read out the expression, how do those fit into a not so dynamic user interface? There was talk of just serializing the expressions into a BLOB, but it would be difficult to walk the expression tree to know what was meant by it.

解决方案(在我的情况)是存储适合用户界面支持的有限数量的参数,并从那里使用该信息即时生成时间表达式(可以在为优化创建时进行序列化)。因此,Schedule类最终会有多个参数,如偏移量,开始日期,结束日期,星期几等等,您可以生成时间表达式来进行辛勤工作。

The solution (in my case) is to store parameters that fit the limited number of cases the User Interface will support, and from there, use that information to generate the Temporal Expressions on the fly (could serialize when created for optimization). So, the Schedule class ends up having several parameters like offset, start date, end date, day of week, and so on... and from that you can generate the Temporal Expressions to do the hard work.

对于具有任务的实例,有一个服务可以生成N天的任务。由于这是与现有系统的集成,因此需要所有实例,这是有道理的。但是,像这样的API可以很容易地用于投影复制,而不会存储所有实例。

As for having instances of the tasks, there is a 'service' that generates tasks for N days. Since this is an integration to an existing system and all instances are needed, this makes sense. However, an API like this can easily be used to project the recurrences without storing all instances.

这篇关于设计问题:您将如何设计一个定期的事件系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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