English 中文(简体)
在一个时间表中模拟无限期承担的任务(类似于铁路的近况)
原标题:Modelling indefinitely-recurring tasks in a schedule (calendar-like rails app)

这已是一个 st脚石。 警告:以下不是问题,而是对我所提出问题的解释。 我的问题是——你们有更好的办法这样做吗? 是否有某种共同的技术,使我不熟悉? 象这样的种子是一个棘手的问题。

So you have Task model. You can create tasks, complete them, destroy them. Then you have recurring tasks. It s just like regular task, but it has a recurrence rule attached to it. However, tasks can recur indefinitely — you can go a year ahead in the schedule, and you should see the task show up.

So when a user creates a recurring task, you don t want to build thousands of tasks for hundred years into the future, and save them to database, right? So I started thinking — how do you create them?

一种办法是,在你看到你的时间表时,建立他们。 因此,当用户提前一个月时,将产生任何经常性任务。 当然,这意味着你只能再用任务数据库记录。 每次关于你以往工作的任务的选任活动都必须在具体日期范围内进行,以便在这一日期范围内启动经常性任务。 这是一种维持和业绩的负担,但是可以做到的。

Alright, but how about the original task? Every recurrent task gets associated with the recurrence rule that created it, and every recurrence rule needs to know the original task that started the recurrence. The latter is important, because you need to clone the original task into new dates as the user browses their schedule. I guess doable too.

但是,如果更新原来的任务,情况如何? 这意味着,我们现在随着时间表的推移,我们将产生与修改后任务相左的经常性任务。 这令人不快。 所有暗含的一再重复的任务都应表明原始任务在增加后如何看待。 因此,我们需要单独储存一份原始任务副本,并作此改动,以便重新开展工作。

然而,当用户完成时间表中的任务时,我们如何知道在某个特定时刻是否需要建立新的重复工作? 我们要求复述规则:“如果我今天坚持任务吗?”而且它说是肯定的。 如果现在已经为这一复发工作任务,我们就没有创造。 除用户外,所有冰层也能够简单地删除自动持续重复的任务之一。 在这种情况下,按照我们的逻辑,该系统将重新确定已删除的任务。 不好。 因此,这意味着我们必须保持这项任务的仓储,但把这项任务作为删除的任务加以标示。 Meh.

As I said in the beginning, I want to know if somebody else tackled this problem and can provide architectural advice here. Does it have to be this messy? Is there anything more elegant I m missing?

Update: Since this question is hard to answer perfectly, I will approve the most helpful insight into design/architecture, which has the best helpfulness/trade-offs ratio for this type of problem. It does not have to encompass all the details.

最佳回答

我知道这是一个老问题,但我刚刚开始研究这个问题,供我自己应用。 我发现,Martin Fowler的论文:“

The main takeaway for me was using what he calls "temporal expressions" to figure out if a booking falls on a certain date range instead of trying to insert an infinite number of events (or in your case tasks) into the database.

实际上,就你而言,这或许意味着你将任务保留在“时间表述”上,即所谓的<密码>。 https://github.com/seejohnrun/ice_cube” 有能力将自己编成活记录的财产,如:

class Task < ActiveRecord::Base
  include IceCube
  serialize :schedule, Hash

  def schedule=(new_schedule)
    write_attribute(:schedule, new_schedule.to_hash)
  end

  def schedule
    Schedule.from_hash(read_attribute(:schedule))
  end
end

冰箱似乎具有真正的灵活性,甚至允许你具体规定重复规则的例外。 (因此,你只想删除一项任务,而并非全部。)

问题在于,你可以真正询问数据库,以便完成具体日期的任务,因为你只储存了完成任务的规则,而不是任务本身。 就我的情况而言,我想增加“威胁——日期”等财产,用于进行某种基本分类/过滤。 即便如此,你也能够把任务推向下个反复出现的地点。 (如果该日期过去了,然后重新启用,则抽查。) 一旦下一个经常性日期过后,你甚至可以储存一份“定型”的任务版本。

这使你的问题“如果任务得到更新”,因为任务一直持续到过去。

无论如何,我希望这对试图通过自己的意愿来考虑这一点的人是有益的。

问题回答

在我处理该问题时,为内部社会网络做了像日历一样的内容。

Tiny bit of background: I needed to book boardrooms for meetings for the entire company. Every boardroom needed to be booked either as a one-off or on a recurring basis. As you ve found out, it s the recurrence rules that kill you. The additional twist to my problem was that there could be conflicts, i.e. two people could try to book the same boardroom for the same date and time.

我将我的模型分为(显然)和(与用户有关的书籍)栏目。 我认为,也有一个加入模式,但这是一个时候。 当用户试图预订一个房间时,就采取了以下做法:

  1. Attempt to book on the first available date (done through the calendar UI by the user similar to how Google Calendar creates events)
  2. If it s a one-off, you re done
  3. If it s a recurring event, try to immediately book the next 6 events based on the rule given (weekly, bi-weekly, monthly); If it fails, due to conflict, book the ones you can, e-mail the conflicts to the user
  4. Book for the next year or up to the date the recurrence is ending in a background job; Follow the conflict resolution rule from #3

在解决冲突时,用户可以选择根据具体情况解决这些冲突,或将剩余的图书转移到新的、可动用的日期和时间。

如果用户更新原始图书(如改变时间和日期),他/她可以选择只更新在重新出版之后的一个或多个。 如果选择了后者,则在删除现有事件后重新启动步骤3和4。

如果这种声音像谷歌日历这样很多,那么你会完全理解我的做法,即:

希望这一帮助。

我个人认为(在我所熟知的神话中)和废墟(我不太清楚,但用的是动态语言,因此我认为概念图1:1),你应当使用发电机。 如何找到最起码的解决办法? 现在,当你提出“国际倡议”时,你就提到发电机,并按要求产生你们所需要的物品。

作为一个接口,它有下个项目和以往的项目方法,并像一个能够通过各种接口向前推进和后退的 cur。 事实上,这是一部不使用无限记忆的法典。

为什么需要扩散物体? 确实需要的是虚拟数据显示控制(网络或台式数据),也称为“发送”,我认为,在网络环境中,你可以认为你的时间表是无限生成的,没有上层,也没有下层。 你们唯一需要能够计算(计算、而不是储存)的数值是现在似乎正确,对用户来说是显而易见的。





相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签