Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6616923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:38:30+00:00 2026-05-25T20:38:30+00:00

I have a couple of rake tasks run in the background using RyanB’s technique

  • 0

I have a couple of rake tasks run in the background using RyanB’s technique from Railscast 127, which work fine locally and on Rails 3, but not on 3.1 in production on Heroku’s cedar stack. Before I rip them out and replace them with delayed_job, should this method of forking a process still work?

  def call_rake(task, options = {})
    options[:rails_env] ||= Rails.env
    args = options.map { |n, v| "#{n.to_s.upcase}='#{v}'" }
    system "rake #{task} #{args.join(' ')} --trace 2>&1 >> #{Rails.root}/log/rake.log &"
  end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:38:31+00:00Added an answer on May 25, 2026 at 8:38 pm

    Answering this myself, after digging around: the system bit does but not the &. Delayed_job is the way to go on this. FWIW here’s my working code to run a rake task in a rails 3.1 app using delayed_job on Heroku’s Cedar stack, to generate an XML file, save it to temp then upload to S3. The XML output file is large, hence the need to handle it asynchronously.

    app/classes/callrake.rb:

    class Callrake
      def call_rake(task, options = {})
          options[:rails_env] ||= Rails.env
          args = options.map { |n, v| "#{n.to_s.upcase}='#{v}'" }
          system "rake #{task} #{args.join(' ')} --trace 2>&1 >> #{Rails.root}/log/rake.log"
    
        end
      handle_asynchronously :call_rake
    end
    

    isbns controller:

    def onixtwo 
    #using Ransack, successor to Metasearch
      @q = Isbn.where(:client_id => current_user.client_id).search(params[:q])
       @isbns = @q.result(:distinct => true)
      if @q.nil? 
         @isbns = Isbn.where(:client_id => current_user.client_id)
      end
      #I have an array to pass so this is a bit hacky - make an array, pass it as a string then turn it back into an array using eval()
      is = []
      @isbns_to_pass = @isbns.each {|isbn| is << isbn.id }
      @client = current_user.client_id   
      @user = current_user.id
      callrake = Callrake.new
      callrake.call_rake(:onixtwo, :isbns => is, :client => @client, :user => @user)
      redirect_to isbns_path, :flash => { :notice => t(:isbnonixtwo).html_safe }
    
    end
    

    slightly off-topic config/locales/en.yml for completeness:

    en:
      isbnonixtwo: "Onix 2.1 message is generating. When it's done, you can download it from the <a href='/onixarchives'>Onix Archive</a> list."
    

    rake task:

    desc "Generate an onix 2.1 xml file"
    task :onixtwo => :environment do |t|
    
    
      client_id = ENV["CLIENT"]
      user_id = ENV["USER"]
      isbns_passed = ENV["ISBNS"]
      isbnsarray = eval(isbns_passed)
      filename = "#{Rails.root}/public/#{Client.find_by_id(client_id).client_name}-#{Date.today}-#{Time.now}-onix-21.xml"    
      isbns = Isbn.find_all_by_id(isbnsarray)
    
     File.open(filename, "w") do |file|
    
        xml = Builder::XmlMarkup.new(:target => file, :indent => 2)
        xml.instruct!(:xml, :version => "1.0", :encoding => "utf-8")
        xml.declare! :DOCTYPE, :ONIXMessage, :SYSTEM, "http://www.editeur.org/onix/2.1/03/reference/onix-international.dtd"
        xml.ONIXMessage do
          xml.Header do 
    #masses of code
    
      end  #of file 
      xmlfile = File.open(filename, "r")
      onx = Onixarchive.new(:client_id => client_id, :user_id => user_id) 
      onx.xml = xmlfile
      onx.save!
      end #of task
    

    Then Onixarchive has a regular paperclip attachment set-up in the model.

    Note the Rails.root.public in the filepath – I kept getting a “does not exist” when I tried to write to app/tmp, because, sure enough when I looked using heroku’s console, there is no tmp folder. I suppose I could have created one, but this app is on cedar, which has an ephemeral filesystem so you can write anywhere for the duration of the session.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's the problem: I have couple of pages which gets its content from a
I have couple of bat files which run further files to build the project.
I have a couple simple rake tasks hosted at github that I would like
I have couple of fields in oracle which is NVARCHAR and I am using
I have couple resource DLLs that I currently load when application starts using following
I have inherited couple of .Net (C#) application which does not have any tracing
I have a couple of tables which look like this Table 1 user_id |
A couple of Rails applications I downloaded have dependencies on bson_ext which appears to
I have couple of forms on my php page. I am using jQuery (&
I'll have couple of python functions I must interface with from the assembly code.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.