managing time sensitive data

1 view
Skip to first unread message

Chubbs

unread,
Nov 4, 2007, 9:54:04 PM11/4/07
to Ruby on Rails: Talk
I am not to sure how to go about doing this, and after any advice on
my problem.

As an example, i would like a similar feature to that of eBay where a
item will have an expiry time and then will be set as closed or etc,
once the time as finished.

So similar i would like a Question to have a week of being open then
after that week it will be set to different status of Resolved or
something. How would i go about checking for this? and making update
queries if the timer reaches zero?

regards,

Andrew Cetinick

Greg Willits

unread,
Nov 4, 2007, 10:18:14 PM11/4/07
to rubyonra...@googlegroups.com

The few times I've needed to do that, I started out thinking I needed
something to actively "close" the record when the time was up. Not so
(that can get quite complicated). All I actually needed was that any
time a process tried to perform a task on that record, that task had
to first see if the expiration time has passed. If so, the task
interprets the record as closed, and acts accordingly.

If you have a lot of tasks that might happen, then you don't
necessarily want to perform that calculation each time, so each task
has the ability to mark a record as closed.

So, now the task process is to first check if the record is closed,
if not, check if it has expired. If yes, then mark it as closed. Now
subsequent tasks will only have to do the first check. I called it a
"lazy close." Of course the code is abstracted out so tasks can use
it w/o duplicating the code that does the work.

It may not be an appropriate strategy for all cases, but it worked
for mine.

-- gw

Chubbs

unread,
Nov 4, 2007, 10:32:43 PM11/4/07
to Ruby on Rails: Talk
thanks for your advice.

ye i was thinking of using an expiry date in the table, but im
confused on when i do the check and updates, cos as you said i wouldnt
want to calculate this each time i get a list of my questions.

"now the task process is to first check if the record is closed".
where would i go about implementing this method, will i do it in my
model for Question (Tasks in ur example )?
how would i implement this? im quite new to rails so dont know the
methods which could accomplish this.

William Pratt

unread,
Nov 4, 2007, 10:52:31 PM11/4/07
to rubyonra...@googlegroups.com
One thought is to create a custom finder method in your model, then
use it in place of find. In that method, you could first do an
update_all on the database using conditions that only update "expired"
questions. This way you need not process any records manually and the
result is limited to a single database call for an arbitrary number of
records. Another option is to call the expiry update_all code from the
controllers before_filter. One note about update_all is that it does
not call any of the model callbacks nor does it check validation.

Hope this helps and I am sure there will be other ideas.

-Bill

Greg Willits

unread,
Nov 4, 2007, 11:07:47 PM11/4/07
to rubyonra...@googlegroups.com
On Nov 4, 2007, at 7:32 PM, Chubbs wrote:

> thanks for your advice.
>
> ye i was thinking of using an expiry date in the table, but im
> confused on when i do the check and updates, cos as you said i wouldnt
> want to calculate this each time i get a list of my questions.
>
> "now the task process is to first check if the record is closed".
> where would i go about implementing this method, will i do it in my
> model for Question (Tasks in ur example )?
> how would i implement this? im quite new to rails so dont know the
> methods which could accomplish this.

Much of the "how" depends on exactly what you're doing, and how
sensitive the exactness of the timing is.

Are you writing a poll system?

-- gw


Chubbs

unread,
Nov 4, 2007, 11:18:35 PM11/4/07
to Ruby on Rails: Talk
ye, a question answer system. question asked, goes into open status,
after one week then goes into expired, then set as resolved or
unresolved.


thanks william. ill try look into using the before_filter to try
implement it.

gene tani

unread,
Nov 4, 2007, 11:22:14 PM11/4/07
to Ruby on Rails: Talk

you could look at acts_as_draftable, REquires approval, and
acts_as_publishable plugins
http://svn.artofmission.com/svn/plugins/requires_approval
http://fr.ivolo.us/posts/acts-as-publishable

Greg Willits

unread,
Nov 5, 2007, 12:55:50 AM11/5/07
to rubyonra...@googlegroups.com
> On Nov 5, 3:07 pm, Greg Willits <li...@gregwillits.ws> wrote:
>> On Nov 4, 2007, at 7:32 PM, Chubbs wrote:
>>
>>> thanks for your advice.
>>
>>> ye i was thinking of using an expiry date in the table, but im
>>> confused on when i do the check and updates, cos as you said i
>>> wouldnt
>>> want to calculate this each time i get a list of my questions.
>>
>>> "now the task process is to first check if the record is closed".
>>> where would i go about implementing this method, will i do it in my
>>> model for Question (Tasks in ur example )?
>>> how would i implement this? im quite new to rails so dont know the
>>> methods which could accomplish this.
>>
>> Much of the "how" depends on exactly what you're doing, and how
>> sensitive the exactness of the timing is.
>>
>> Are you writing a poll system?

On Nov 4, 2007, at 8:18 PM, Chubbs wrote:
> ye, a question answer system. question asked, goes into open status,
> after one week then goes into expired, then set as resolved or
> unresolved.


Seems to me you just need a date column that represents the date and
time that the question is considered closed. When you do queries you
include a conditional element which identifies whether you want
records where closedDate is > today or < today.

"show me open questions" would have a "WHERE closedDate >= today"

-- gw


Reply all
Reply to author
Forward
0 new messages