gpt4 book ai didi

heroku - Rails 3 Mailer 和延迟作业 & Heroku

转载 作者:行者123 更新时间:2023-12-02 07:42:20 28 4
gpt4 key购买 nike

我遇到了这个错误
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,而在于 hirefire,如果我删除 hirefire gem,作业就会排队,我手动运行 worker 一切正常。我只是无法让 hirefire 工作。

最佳答案

Cedar 堆栈补丁 https://gist.github.com/1082673是一个好的开始,但需要更新以使用最新的 heroku-api 接口(interface)。这是我正在使用的补丁,效果很好。

要使用它,您需要设置两个 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

关于heroku - Rails 3 Mailer 和延迟作业 & Heroku,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9830629/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com