【问题标题】:Rails 3 Mailer and Delayed Job & HerokuRails 3 Mailer 和延迟作业和 Heroku
【发布时间】:2012-03-22 21:13:41
【问题描述】:

我收到此错误
ArgumentError(信息需要 name_or_domain): 我正在使用delayed_job hidefire 和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,而在于hirefire,如果我删除了hirefire gem,工作就会排队,我手动运行worker,所有工作都像魅力一样。我就是无法让雇佣火工作。

【问题讨论】:

    标签: heroku delayed-job


    【解决方案1】:

    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
    

    然后添加以下内容:

    config/initializer/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
    

    【讨论】:

      【解决方案2】:

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

      【讨论】:

      • 非常感谢我在搜索时发现了它。我希望将它包含在 Gem 中。无论如何,非常感谢:)
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-08
      • 1970-01-01
      • 1970-01-01
      • 2013-08-04
      • 2015-09-08
      • 2012-09-14
      相关资源
      最近更新 更多