# Multithreaded BG task which does AR updates okay?

**URL:** <https://www.ruby-forum.com/t/multithreaded-bg-task-which-does-ar-updates-okay/168533>\
**Category:** Rails\
**Created:** [May 22, 2009, 3:06am UTC](https://www.ruby-forum.com/t/multithreaded-bg-task-which-does-ar-updates-okay/168533 "2009-05-22T03:06:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![timhunter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/71e660/32.png) [@timhunter](https://www.ruby-forum.com/u/timhunter)\
**Post date:** [May 22, 2009, 3:06am UTC](https://www.ruby-forum.com/t/multithreaded-bg-task-which-does-ar-updates-okay/168533/1 "2009-05-22T03:06:59Z")

</div>

Hey guys,

I’m thinking about writing a method which utilises multithreading to  
do a bunch of api  
calls and make AR updates. Then calling the method once an hour with  
Rufus scheduler.

I’m a little concerned if this is safe or not, and I’m wondering if  
anyone has any insight? I guess the main topic is does multithreading  
work nicely with AR - but I’m also wondering if using rufus turns it  
in to a more complicated question?

Has anyone seen good articles discussing it?

Cheers,

Tim.

---

<div class="post-metadata">

**Author:** ![timhunter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/71e660/32.png) [@timhunter](https://www.ruby-forum.com/u/timhunter)\
**Post date:** [May 22, 2009, 3:43am UTC](https://www.ruby-forum.com/t/multithreaded-bg-task-which-does-ar-updates-okay/168533/2 "2009-05-22T03:43:52Z")

</div>

What we do is to write a rake task that make AR update, and add this  
running  
task into cron job, it’s easy and safe.

On Fri, May 22, 2009 at 9:06 AM, Tim H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> work nicely with AR - but I’m also wondering if using rufus turns it  
> in to a more complicated question?
> 
> Has anyone seen good articles discussing it?
> 
> Cheers,
> 
> Tim.
> 
> >

–  
My home: [http://www.huangzhimin.com](http://www.huangzhimin.com)

---

<div class="post-metadata">

**Author:** ![timhunter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/71e660/32.png) [@timhunter](https://www.ruby-forum.com/u/timhunter)\
**Post date:** [May 22, 2009, 9:18am UTC](https://www.ruby-forum.com/t/multithreaded-bg-task-which-does-ar-updates-okay/168533/3 "2009-05-22T09:18:56Z")

</div>

On May 22, 2:06 am, Tim H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hey guys,
> 
> I’m thinking about writing a method which utilises multithreading to  
> do a bunch of api  
> calls and make AR updates. Then calling the method once an hour with  
> Rufus scheduler.

On earlier version of rails you need to explicitly safe that you want  
AR to be threadsafe (the setting is called allow\_concurrency). This  
isn’t needed from rails 2.2 is my memory is correct.

Fred
