Rails 3 Mailer和延迟工作& Heroku的

时间:2012-03-22 21:13:41

标签: heroku delayed-job

我收到此错误     ArgumentError(信息需要name_or_domain): 我正在使用delayed_job hirefire和heroku。以下是我的代码中的行

Notifier.delay.notify(self.artist, commented_on_artist, self.project, self.work_id)

当我使用以下代码时,一切都很完美

Notifier.delay(self.artist, commented_on_artist, self.project, self.work_id).deliver

错误来自此函数的heroku gem中的Client.rb     #在应用上显示模式,自定义域和协作者等信息。

def info(name_or_domain)
    raise ArgumentError.new("name_or_domain is required for info") unless name_or_domain
    name_or_domain = name_or_domain.gsub(/^(http:\/\/)?(www\.)?/, '')
    doc = xml(get("/apps/#{name_or_domain}").to_s)
    attrs = hash_from_xml_doc(doc)[:app]
    attrs.merge!(:collaborators => list_collaborators(attrs[:name]))
    attrs.merge!(:addons        => installed_addons(attrs[:name]))
end

我刚刚尝试了一些事情并且意识到问题不在于delayed_job它与雇佣火灾,如果我删除雇佣宝石工作排队,我手动运行工人所有工作就像一个魅力。我无法让雇佣工作。

2 个答案:

答案 0 :(得分:5)

Cedar堆栈补丁https://gist.github.com/1082673是一个良好的开端,但需要更新才能使用最新的heroku-api界面。这是我正在使用的补丁,运行良好。

要使用它,您需要设置两个Heroku环境变量:

heroku config:set APP_NAME=your-heroku-app-name HEROKU_API_KEY=your-heroku-api-key

然后添加以下内容:

<强>配置/初始化/ hirefire.rb

require 'heroku-api'
module HireFire
  module Environment
    class Heroku < Base

      private

      ##
      # Either retrieves the amount of currently running workers,
      # or set the amount of workers to a specific amount by providing a value
      #
      # @overload workers(amount = nil)
      #   @param [Fixnum] amount will tell heroku to run N workers
      #   @return [nil]
      # @overload workers(amount = nil)
      #   @param [nil] amount
      #   @return [Fixnum] will request the amount of currently running workers from Heroku
      def workers(amount = nil)

        #
        # Returns the amount of Delayed Job
        # workers that are currently running on Heroku
        if amount.nil?
          return heroku.get_ps(ENV['APP_NAME']).body.select {|p| p['process'] =~ /worker.[0-9]+/}.length
        end

        ##
        # Sets the amount of Delayed Job
        # workers that need to be running on Heroku
        return heroku.post_ps_scale(ENV['APP_NAME'], "worker", amount)

      rescue ::Heroku::API::Errors::Error
        HireFire::Logger.message("Worker query request failed with #{ $!.class.name } #{ $!.message }")
        nil
      end

      ##
      # Get the heroku connection. Needs to have the HEROKU_API_KEY in the environment
      def heroku(api_key = nil)
        @heroku ||= ::Heroku::API.new(:api_key => api_key || ENV['HEROKU_API_KEY'])
      end

    end
  end
end

答案 1 :(得分:2)

你看过Cedar堆栈补丁吗? https://gist.github.com/1082673