# Managing time sensitive data

**URL:** <https://www.ruby-forum.com/t/managing-time-sensitive-data/119220>\
**Category:** Rails\
**Created:** [November 5, 2007, 3:54am UTC](https://www.ruby-forum.com/t/managing-time-sensitive-data/119220 "2007-11-05T03:54:39Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chubbs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/47e85d/32.png) [@Chubbs](https://www.ruby-forum.com/u/Chubbs)\
**Post date:** [November 5, 2007, 3:54am UTC](https://www.ruby-forum.com/t/managing-time-sensitive-data/119220/1 "2007-11-05T03:54:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Chubbs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/47e85d/32.png) [@Chubbs](https://www.ruby-forum.com/u/Chubbs)\
**Post date:** [November 5, 2007, 4:18am UTC](https://www.ruby-forum.com/t/managing-time-sensitive-data/119220/2 "2007-11-05T04:18:37Z")

</div>

On Nov 4, 2007, at 6:54 PM, Chubbs wrote:

> queries if the timer reaches zero?  
> 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

---

<div class="post-metadata">

**Author:** ![Chubbs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/47e85d/32.png) [@Chubbs](https://www.ruby-forum.com/u/Chubbs)\
**Post date:** [November 5, 2007, 4:33am UTC](https://www.ruby-forum.com/t/managing-time-sensitive-data/119220/3 "2007-11-05T04:33:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Chubbs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/47e85d/32.png) [@Chubbs](https://www.ruby-forum.com/u/Chubbs)\
**Post date:** [November 5, 2007, 5:08am UTC](https://www.ruby-forum.com/t/managing-time-sensitive-data/119220/4 "2007-11-05T05:08:18Z")

</div>

On Nov 4, 2007, at 7:32 PM, Chubbs wrote:

> 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

---

<div class="post-metadata">

**Author:** ![Chubbs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/47e85d/32.png) [@Chubbs](https://www.ruby-forum.com/u/Chubbs)\
**Post date:** [November 5, 2007, 4:53am UTC](https://www.ruby-forum.com/t/managing-time-sensitive-data/119220/5 "2007-11-05T04:53:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Chubbs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/47e85d/32.png) [@Chubbs](https://www.ruby-forum.com/u/Chubbs)\
**Post date:** [November 5, 2007, 5:19am UTC](https://www.ruby-forum.com/t/managing-time-sensitive-data/119220/6 "2007-11-05T05:19:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Chubbs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/47e85d/32.png) [@Chubbs](https://www.ruby-forum.com/u/Chubbs)\
**Post date:** [November 5, 2007, 6:56am UTC](https://www.ruby-forum.com/t/managing-time-sensitive-data/119220/7 "2007-11-05T06:56:21Z")

</div>

> > > “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

---

<div class="post-metadata">

**Author:** ![Chubbs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/47e85d/32.png) [@Chubbs](https://www.ruby-forum.com/u/Chubbs)\
**Post date:** [November 5, 2007, 5:22am UTC](https://www.ruby-forum.com/t/managing-time-sensitive-data/119220/8 "2007-11-05T05:22:54Z")

</div>

On Nov 4, 6:54 pm, Chubbs [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> queries if the timer reaches zero?
> 
> regards,
> 
> Andrew Cetinick

you could look at acts\_as\_draftable, REquires approval, and  
acts\_as\_publishable plugins  
[http://svn.artofmission.com/svn/plugins/requires\_approval](http://svn.artofmission.com/svn/plugins/requires_approval)  
[http://fr.ivolo.us/posts/acts-as-publishable](http://fr.ivolo.us/posts/acts-as-publishable)
