Heroku错误:ArgumentError:无效的uri方案''

时间:2016-08-03 21:47:52

标签: heroku redis sidekiq redistogo

我试图让我的Rails应用程序使用Sidekiq处理后台作业,并将Sidekiq与Heroku上的redis-to-go连接起来。这是我的Procfile

web: bundle exec puma -C config/puma.rb
worker: bundle exec -C config/sidekiq.yml

这是我的Sidekiq.rb初始化文件:

require 'sidekiq'

Sidekiq.configure_client do |config|  
  config.redis = { url: ENV['REDIS_PROVIDER'] }
end 

Sidekiq.configure_client do |config|  
   config.redis = { url: ENV['REDIS_PROVIDER'] }
end

Heroku中的REDIS_PROVIDER变量设置为REDISTOGO_URL。根据提供的说明here,我还添加了一个初始化文件redis.rb。以下是内容:

uri = URI.parse(ENV["REDIS_PROVIDER"])
REDIS = Redis.new(:url => uri)

我收到以下错误,但不确定如何解决。 Heroku也抛出H10错误

[3] ! Unable to load application: ArgumentError: invalid uri scheme '

/app/vendor/bundle/ruby/2.2.0/gems/redis-3.3.0/lib/redis/client.rb:416:in `_parse_options': invalid uri scheme '' (ArgumentError) 

更新:

我回滚到Heroku上的先前版本并从gemfile中删除了redis gem,删除了redis intializer文件,应用程序不再崩溃。但是,后台工作仍然无法正常工作,而且我在日志中收到了这些错误:

heroku/worker.1:  Starting process with command `bundle exec -C config/sidekiq.yml`
heroku/worker.1:  State changed from starting to up
app/worker.1:  bundler: command not found: -C 
heroku/worker.1:  Process exited with status 127 
heroku/worker.1:  State changed from up to crashed 
app/worker.1:  Install missing gem executables with `bundle install` 

为什么系统不接受导致工作程序崩溃的config参数?

无效的uri方案的错误仍然存​​在:

app/web.1:  Completed 500 Internal Server Error in 303ms (ActiveRecord: 0.0ms) 
app/web.1:  ArgumentError (invalid uri scheme ''): 

sidekiq.yml文件

# Sample configuration file for Sidekiq.
# Options here can still be overridden by cmd line args.
# Place this file at config/sidekiq.yml and Sidekiq will
# pick it up automatically.
---
:verbose: false
:concurrency: 10

# Set timeout to 8 on Heroku, longer if you manage your own systems.

:超时:8

# Sidekiq will run this file through ERB when reading it so you can
# even put in dynamic logic, like a host-specific queue.
# http://www.mikeperham.com/2013/11/13/advanced-sidekiq-host-specific-queues/
:queues:
  - critical
  - default
  - low

# you can override concurrency based on environment

生产:       :并发:25    分期:       :并发:10

3 个答案:

答案 0 :(得分:3)

您正在错误地使用REDIS_PROVIDER。请再次查看文档。

https://github.com/mperham/sidekiq/wiki/Using-Redis#using-an-env-variable

答案 1 :(得分:0)

通过将redis.rb和sidekiq.rb中的redis URL引用更改为相同的Redis,我能够纠正我的应用程序中失败的Heroku部署和router-view错误(Rails 6,Ruby 2.7.2) Cloud ENV变量。

堆栈跟踪为:

ArgumentError: invalid uri scheme ''

一旦我在Heroku配置中将所有redis url引用都更改为Redis Cloud URL,我的应用便成功部署:

redis.rb

remote:        Running: rake assets:precompile
remote:        rake aborted!
remote:        ArgumentError: invalid uri scheme ''
remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/redis-4.2.2/lib/redis/client.rb:436:in `_parse_options'
remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/redis-4.2.2/lib/redis/client.rb:84:in `initialize'
remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/redis-4.2.2/lib/redis.rb:62:in `new'
remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/redis-4.2.2/lib/redis.rb:62:in `initialize'
remote:        /tmp/build_961a7a51/config/initializers/redis.rb:4:in `new'
remote:        /tmp/build_961a7a51/config/initializers/redis.rb:4:in `<top (required)>'
remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/activesupport-6.0.3.4/lib/active_support/dependencies.rb:318:in `load'
remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/activesupport-6.0.3.4/lib/active_support/dependencies.rb:318:in `block in load'
remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/activesupport-6.0.3.4/lib/active_support/dependencies.rb:291:in `load_dependency'
remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/activesupport-6.0.3.4/lib/active_support/dependencies.rb:318:in `load'
remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/railties-6.0.3.4/lib/rails/engine.rb:666:in `block in load_config_initializer'
remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/activesupport-6.0.3.4/lib/active_support/notifications.rb:182:in `instrument'
remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/railties-6.0.3.4/lib/rails/engine.rb:665:in `load_config_initializer'
remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/railties-6.0.3.4/lib/rails/engine.rb:625:in `block (2 levels) in <class:Engine>'
remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/railties-6.0.3.4/lib/rails/engine.rb:624:in `each'
remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/railties-6.0.3.4/lib/rails/engine.rb:624:in `block in <class:Engine>'
remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/railties-6.0.3.4/lib/rails/initializable.rb:32:in `instance_exec'
remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/railties-6.0.3.4/lib/rails/initializable.rb:32:in `run'
remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/railties-6.0.3.4/lib/rails/initializable.rb:61:in `block in run_initializers'
remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/railties-6.0.3.4/lib/rails/initializable.rb:50:in `each'
remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/railties-6.0.3.4/lib/rails/initializable.rb:50:in `tsort_each_child'
remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/railties-6.0.3.4/lib/rails/initializable.rb:60:in `run_initializers'
remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/railties-6.0.3.4/lib/rails/application.rb:363:in `initialize!'
remote:        /tmp/build_961a7a51/config/environment.rb:5:in `<top (required)>'
remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/zeitwerk-2.4.0/lib/zeitwerk/kernel.rb:34:in `require'
remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/zeitwerk-2.4.0/lib/zeitwerk/kernel.rb:34:in `require'
remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/activesupport-6.0.3.4/lib/active_support/dependencies.rb:324:in `block in require'
remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/activesupport-6.0.3.4/lib/active_support/dependencies.rb:291:in `load_dependency'
remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/activesupport-6.0.3.4/lib/active_support/dependencies.rb:324:in `require'
remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/railties-6.0.3.4/lib/rails/application.rb:339:in `require_environment!'
remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/railties-6.0.3.4/lib/rails/application.rb:523:in `block in run_tasks_blocks'
remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/sprockets-rails-3.2.2/lib/sprockets/rails/task.rb:61:in `block (2 levels) in define'
remote:        Tasks: TOP => environment
remote:        (See full trace by running task with --trace)
remote:
remote:  !
remote:  !     Precompiling assets failed.
remote:  !
remote:  !     Push rejected, failed to compile Ruby app.
remote:
remote:  !     Push failed

sidekiq.rb

if ENV["REDISCLOUD_CRIMSON_URL"]
    $redis = Redis.new(:url => ENV["REDISCLOUD_CRIMSON_URL"])
end

在Heroku设置中,REDIS_URL和REDIS_PROVIDER环境变量也设置为REDISCLOUD_CRIMSON_URL(变量,不是实际值)。希望这会有所帮助。

答案 2 :(得分:0)

TL;DR; 如果您在本地使用 Sidekiq/Redis 有问题,请将 redis URI 定义为 SIDEKIQ_REDIS_URL=redis://localhost:6379

文档说 Sidekiq 会尝试连接到 localhost:6379,这可能是真的,但他们遗漏了一个小细节。 URI 方案不是 httphttps,而是 redis

在我的配置中,我试图传递我在 .env 文件中设置的具体 SIDEKIQ_REDIS_URL

Sidekiq.configure_server do |config|
    config.redis = { url: ENV.fetch('SIDEKIQ_REDIS_URL'), size: 12, network_timeout: 5 }
end

现在,如果您不在 .env 中声明 SIDEKIQ_REDIS_URL,当然它不会起作用。更重要的是,即使你添加了默认的 URI,它也会失败:

SIDEKIQ_REDIS_URL=localhost:6379

它会抱怨 URI 方案

似乎URI方案不是httphttps,而是redis:

SIDEKIQ_REDIS_URL=redis://localhost:6379