# Delayed\_Job and Setting Env

**URL:** <https://www.ruby-forum.com/t/delayed-job-and-setting-env/163325>\
**Category:** Rails\
**Created:** [March 19, 2009, 8:50am UTC](https://www.ruby-forum.com/t/delayed-job-and-setting-env/163325 "2009-03-19T08:50:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sshefer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d9b06d/32.png) [@sshefer](https://www.ruby-forum.com/u/sshefer)\
**Post date:** [March 19, 2009, 8:50am UTC](https://www.ruby-forum.com/t/delayed-job-and-setting-env/163325/1 "2009-03-19T08:50:49Z")

</div>

Hi,

I am setting up a background task using delayed job to upload some of  
my documents up to scribd from my S3 bucket.

The problem I encounter is that I get an error saying:  
Job failed with RightAws::AwsError: AWS access keys are required to  
operate on S3

I realize that this is because my job doesn’t know what environment  
I’m in so I explicitly set it in the class (ENV[‘RAILS\_ENV’] =  
“development”). There has to be a better way of doing this so that I  
don’t need to to change this every time.

Is there a better way of doing this? Am I not putting this in the  
right place?

Thanks

============= Code Snippet Below =============

class Job (in lib/script\_job.rb)  
attr\_accessor :document\_id

ENV[‘RAILS\_ENV’] = “development”

def initialize(document)  
self.document\_id = document.id  
end

def perform  
document = Document.find(document\_id)  
Scribd::API.instance.key = APP\_CONFIG[:scribd\_api\_key]  
Scribd::API.instance.secret = APP\_CONFIG[:scribd\_api\_secret]  
Scribd::User.login APP\_CONFIG[:scribd\_user], APP\_CONFIG  
[:scribd\_password]  
upload = Scribd::Document.upload(:file =\> document.s3\_url,  
:type =\> return\_doc\_type  
(document.content\_type))  
…  
end  
end
