- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我正在编写一个应用程序,它需要发送许多电子邮件并因为这些电子邮件而创建许多用户通知。此任务在 Heroku 中产生超时。为了解决这个问题,我决定使用 Resque 和 RedistToGo。
我所做的是发送电子邮件(它实际上只是一封电子邮件,因为我们使用 Sendgrid 来处理它)并使用 Resque worker 创建通知。电子邮件已创建,因此我将其 ID 连同所有收件人发送给工作人员。
这在本地运行良好。在生产环境中,除非我们在 Heroku 中重启我们的应用程序,否则它只会运行一次。我将发布一些我的代码和错误消息:
#lib/tasks/resque.rake
require 'resque/tasks'
task "resque:setup" => :environment do
ENV['QUEUE'] = '*'
end
desc "Alias for resque:work (To run workers on Heroku)"
task "jobs:work" => "resque:work"
#config/initalizers/resque.rb
ENV["REDISTOGO_URL"] ||= "redis://redistogo:some_hash@some_url:some_number/"
uri = URI.parse(ENV["REDISTOGO_URL"])
Resque.redis = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
Dir["#{Rails.root}/app/workers/*.rb"].each { |file| require file }
#app/workers/massive_email_sender.rb
class MassiveEmailSender
@queue = :massive_email_queue
def self.perform(email_id, recipients)
email = Email.find(email_id.to_i)
email.recipients = recipients
email.send_email
end
end
我有一个 Email 模型,它有一个 after_create 可以让工作人员排队:
class Email < ActiveRecord::Base
...
after_create :enqueue_email
def enqueue_email
Resque.enqueue(MassiveEmailSender, self.id, self.recipients)
end
...
end
这个 Email 模型还有 send_email
方法,它完成我之前所说的
我收到以下错误消息。我要发布 Resque 给我的所有信息:
Worker
9dddd06a-2158-464a-b3d9-b2d16380afcf:1 on massive_email_queue at just now
Retry or Remove
Class
MassiveEmailSender
Arguments
21
["some_email_1@gmail.com", "some_email_2@gmail.com"]
Exception
ActiveRecord::StatementInvalid
Error
PG::Error: SSL error: decryption failed or bad record mac : SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull FROM pg_attribute a LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum WHERE a.attrelid = '"emails"'::regclass AND a.attnum > 0 AND NOT a.attisdropped ORDER BY a.attnum
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:1139:in `async_exec'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:1139:in `exec_no_cache'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:663:in `block in exec_query'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
/app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.2/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
/app/vendor/bundle/ruby/1.9.1/gems/newrelic_rpm-3.3.2/lib/new_relic/agent/instrumentation/active_record.rb:31:in `block in log_with_newrelic_instrumentation'
/app/vendor/bundle/ruby/1.9.1/gems/newrelic_rpm-3.3.2/lib/new_relic/agent/method_tracer.rb:242:in `trace_execution_scoped'
/app/vendor/bundle/ruby/1.9.1/gems/newrelic_rpm-3.3.2/lib/new_relic/agent/instrumentation/active_record.rb:28:in `log_with_newrelic_instrumentation'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:662:in `exec_query'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:1264:in `column_definitions'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:858:in `columns'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.2/lib/active_record/connection_adapters/schema_cache.rb:12:in `block in initialize'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.2/lib/active_record/model_schema.rb:228:in `yield'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.2/lib/active_record/model_schema.rb:228:in `default'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.2/lib/active_record/model_schema.rb:228:in `columns'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.2/lib/active_record/model_schema.rb:237:in `columns_hash'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.2/lib/active_record/relation/delegation.rb:7:in `columns_hash'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.2/lib/active_record/relation/finder_methods.rb:330:in `find_one'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.2/lib/active_record/relation/finder_methods.rb:311:in `find_with_ids'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.2/lib/active_record/relation/finder_methods.rb:107:in `find'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.2/lib/active_record/querying.rb:5:in `find'
/app/app/workers/massive_email_sender.rb:5:in `perform'
据此,第一个参数是电子邮件 ID,第二个参数是所有收件人的列表……完全正确。
谁能帮帮我?谢谢!
最佳答案
我遇到了同样的问题。假设您正在使用 Active Record,您必须为每个 fork 的 Resque worker 调用 ActiveRecord::Base.establish_connection
以确保它没有陈旧的数据库连接。尝试将其放入您的 lib/tasks/resque.rake
task "resque:setup" => :environment do
ENV['QUEUE'] = '*'
Resque.after_fork = Proc.new { ActiveRecord::Base.establish_connection }
end
关于ruby-on-rails-3 - Resque with Rails 3 + Heroku + RedisToGo 给出 Postgresql 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9915146/
我用coffee-resque创建了一些worker,并尝试使用resque-web的ruby版本查看worker,但只看到间歇性的worker闪进闪出。 我注意到咖啡风格在暂停时会取消对 worke
假设这是我的 worker : class FooWorker @queue = :foo def self.perform User.all.each do |u| ..
我对 resque 很陌生,但它看起来非常适合我的需求。 实际上,我正在尝试设置一个简单的测试应用程序,例如: require 'resque' require 'resque/job_with_st
我正在使用 Resque 和 Resque 调度程序,但是当我输入命令时 resque-web它没有运行。而是提示错误: bash: resque-web: command not found So
我正在使用 ruby on rails 构建一个 webapp,它需要在后台运行 C++ exe 程序。我为此比较了 3 个最常用的 gem(Delayed_Jobs、Resque、Sidekiq
我想知道 resque-scheduler 是否需要一个 resque 实例来运行特定队列中的作业,或者 resque-scheduler 必须使用 resque:work 任务。 提前致谢。 最佳答
我正在使用 Resque、Resque-Status 和 Resque-Retry 来处理 bkg 作业。以下是一个示例作业。它针对 4-5 个模型执行查询。现在我想尝试使用 Sidekiq它以其超过
我正在开发一个使用 resque 的 rails 应用程序和 resque-scheduler 安排电子邮件发送。 有没有办法获得所有预定作业的列表,或者更好的具有特定参数的作业列表? 我尝试了一些类
将 Resque 与 Redis 结合使用 我一直收到 Redis 的 OOM 命令在使用内存时不允许 > 'maxmemory' 错误。现在很明显,我似乎应该将 redis 的内存从当前的 500M
此外,管理内置“管理结构”(如标题中的结构)的 Resque 的最佳实践是什么?我应该用 jedis.del(String key) 或类似的东西清除它们吗? 最佳答案 resque:failed 是
我有 resque-scheduler 在 Rails 应用程序中运行良好。现在我需要能够从队列中跟踪状态并删除作业。我简要地查看了 resque-status,据我所见,如果我能让它与 resque
我都关注了 instructions on resque-scheduler repo在 resque-web 界面上显示“延迟”和“计划”选项卡,但什么也没有! 这是进口的 gem : gem 'r
我已经为我的应用程序设置了 Resque.redis.namespace,现在 resque-web 不再显示工作人员和队列。 有什么方法可以让 resque-web 知道 redis.namespa
我一直试图让 Resque(使用 Resque 服务器)和 RedisToGo 在 heroku(cedar)上工作一段时间,但我一直遇到这个错误: Redis::CannotConnectError
我在 resque 工作中遇到了一个奇怪的问题,我想知道是否有其他人遇到过。 我们在 jruby 1.6.2 下运行 resque 我们有一个长时间 运行任务,它从各种 URL 下载一堆文件,使用 F
我刚刚看了这个关于 Resque 的惊人的 railscast .在我启动 redis 服务器并启动 workers 之后: rake environment resque:work QUEUE="*
我使用 resque-history 插件来监控已完成的任务。 首先,我将这个字符串 require 'resque-history/server' 包含到路由文件中,然后我在仪表板中看到了新的历史记
我需要启动 4 个 resque 工作人员,所以我使用了以下命令 bundle exec rake environment resque:workers RAILS_ENV=production CO
我有几个 Resque 作业在运行,每个都在一个单独的终端窗口中启动,如下所示: QUEUE=queue_1 rake environment resque:work QUEUE=queue_2 ra
我有以下代码。它的工作是根据通过浏览器(使用 Sinatra)提供的数据发送电子邮件。它会在 20 秒后向给定的地址发送一封电子邮件。当我运行该程序时,它会立即发送电子邮件,而无需等待时间。谁能帮我解
我是一名优秀的程序员,十分优秀!