我有一个Ruby on Rails应用程序,我正在运行Mac OS X 10.6的计算机上部署.出现问题的代码由delayed_job运行.只有当它通过delayed_job运行时才会出现此问题.如果我在控制台(rails console production)中运行它或直接通过cURL调用API,它可以正常工作.此外,整个过程在我的开发环境中没有问题.
基本上,代码在一个地方工作,但由于某种原因,在必须工作的地方失败.我搜索并找到了一些资源,但没有一个建议适用或有任何区别.当我登录服务器并运行命令时,一切正常.但由于某些原因,当它们由Capistrano运行/启动时,它不起作用.
任何帮助是极大的赞赏.
重要笔记:
码:
class CallApi < Struct.new(:num)
def perform
log "Entering perform"
apinum = num || 5
log "ApiNum = #{apinum}"
results = attempt(2,10) do
ActiveSupport::JSON.decode(RestClient.get(API_URL, {:params => {:apinum => apinum}}))
end
log "Results retrieved. (count: #{results.count})"
end
def log(message)
Delayed::Worker.logger.info "[CallApi] #{Time.now} - #{message}"
end
end
Run Code Online (Sandbox Code Playgroud)
环境配置(注意:网址是假的,但形式与真实网址相同):
API_URL = "http://api.example.org/api_endpoint"
# Originally, I had "http://" before the beginning, but found a …Run Code Online (Sandbox Code Playgroud)