# Backgroundrb - how to pass a data file to worker from form

**URL:** <https://www.ruby-forum.com/t/backgroundrb-how-to-pass-a-data-file-to-worker-from-form/72416>\
**Category:** Rails\
**Created:** [October 17, 2006, 4:20am UTC](https://www.ruby-forum.com/t/backgroundrb-how-to-pass-a-data-file-to-worker-from-form/72416 "2006-10-17T04:20:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nathandelane](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/df705f/32.png) [@nathandelane](https://www.ruby-forum.com/u/nathandelane)\
**Post date:** [October 17, 2006, 4:20am UTC](https://www.ruby-forum.com/t/backgroundrb-how-to-pass-a-data-file-to-worker-from-form/72416/1 "2006-10-17T04:20:52Z")

</div>

I am trying to initiate a background process with several parameters  
including a CSV file. Can anyone provide an example where a file is  
used as input for the background worker?

Thanks,  
Nathan

---

<div class="post-metadata">

**Author:** ![nathandelane](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/df705f/32.png) [@nathandelane](https://www.ruby-forum.com/u/nathandelane)\
**Post date:** [October 17, 2006, 4:28am UTC](https://www.ruby-forum.com/t/backgroundrb-how-to-pass-a-data-file-to-worker-from-form/72416/2 "2006-10-17T04:28:54Z")

</div>

On Oct 16, 2006, at 7:22 PM, Nathan L. wrote:

> I am trying to initiate a background process with several parameters  
> including a CSV file. Can anyone provide an example where a file is  
> used as input for the background worker?
> 
> Thanks,  
> Nathan

Nathan-

```
I would suggest just sending the filename to the worker and have the

```

worker open the file and deal with the contents.

– Ezra Z.  
– Lead Rails Architect  
– removed\_email\_address@domain.invalid  
– Engine Y., Serious Rails Hosting  
– (866) 518-YARD (9273)

---

<div class="post-metadata">

**Author:** ![nathandelane](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/df705f/32.png) [@nathandelane](https://www.ruby-forum.com/u/nathandelane)\
**Post date:** [October 17, 2006, 4:52am UTC](https://www.ruby-forum.com/t/backgroundrb-how-to-pass-a-data-file-to-worker-from-form/72416/3 "2006-10-17T04:52:58Z")

</div>

Ezra,

Thanks for the tip. The problem was that I was getting that “connection  
refused” when trying to open the file for reading. I found that passing  
in the file contents as an array works. Just wondering if there is a  
better way. I will look for ways around the connection error.

Also, as a follow up (if you don’t mind sharing), what is the preferred  
method for ensuring that the background server is started/running at all  
times? The environment is Fedora Core 5.

Thanks!  
Nathan

---

<div class="post-metadata">

**Author:** ![nathandelane](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/df705f/32.png) [@nathandelane](https://www.ruby-forum.com/u/nathandelane)\
**Post date:** [October 17, 2006, 5:23pm UTC](https://www.ruby-forum.com/t/backgroundrb-how-to-pass-a-data-file-to-worker-from-form/72416/4 "2006-10-17T17:23:00Z")

</div>

On Mon, 2006-10-16 at 22:54 -0400, Nathan L. wrote:

> > > used as input for the background worker?

All,

I got this working using Ezra’s comments and the ‘tempfile’ idea  
suggested in “Ruby Cookbook”. Thought there might be others that want  
to accomplish similar things. I don’t want to clog the list, so here’s  
a summary…

The form handler controller passes the multi-part file data to a temp  
file on the server file system, then passes the file dir/name to the  
background worker process. The worker re-reads the data and performs  
the main work…in this case updating a Postgresql database with about  
100k records.

If anyone wants details or code samples, please contact me off list.  
Also, if there are suggestions for improvements I could make, please let  
me know!

Thanks,  
Nathan
