Forum: Ruby on Rails Delayed_Job and Setting Env

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
6f3a904bebab756df4880aeb199da396?d=identicon&s=25 sshefer (Guest)
on 2009-03-19 08:50
(Received via mailing list)
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
This topic is locked and can not be replied to.