Tag: rails activejob

Sidekiq没有找到Rails Active Job的记录

在模型中创建用户之后,作业将排队等待 user.rb after_create_commit :profile_photo_job def profile_photo_job message = “Add a profile photo” ReminderJob.set(wait: 1800).perform_later(self.id.to_s, message) end reminder_job.rb class ReminderJob < ApplicationJob queue_as :default def perform(user_id, message) if user_id user = User.find(user_id) end ##sending message notification here end end 但是,它经常在我的sidekiq控制台中抛出以下错误 ActiveRecord :: RecordNotFound:找不到’id’= 7749的用户处理器:User-MacBook-Pro.local:***** 生产中发生此错误。

每当我在我的Rails 4.2.1应用程序中单击使用Payola-Payment Gem(为Stripe制作的gem)付款时,我都会收到“待定错误”

使用Payola-Payments Gem处理Stripe Payments,有必要为您的交易设置后台工作程序。 使用ActiveJob设置后台工作程序后,单击付款时会出现错误。 这是它 : 注意:我使用的是Windows环境(Windows 8),我相信这里有些问题。 我的视图上的错误警报渲染: 这似乎花了太长时间。 请联系支持并给他们交易ID:ook4dp 以下是Console生成的代码 Started POST “/payola/buy/job/excelwithcode-7d492bf330ab66b0eaa61ce2ce277e14” for 127.0.0.1 at 2016-04-25 20:50:26 +0100 Processing by Payola::TransactionsController#create as */* Parameters: {“stripeToken”=>”tok_184FksCc1zXXaitaOrD5ELaH”, “stripeEmail”=>”neededforpayments@mybusinesstest.com”, “authenticity_token”=>”Uod7Ue4XHNcCvayA6G1shiiI43QKoBOrbImnwt0TGFHVlp11WdHaNTcPl/0UyYefcT6foowc30bFdtK0cJuXog==”, “product_class”=>”job”, “permalink”=>”excelwithcode-7d492bf330ab66b0eaa61ce2ce277e14”} Payola::Affiliate Load (1.0ms) SELECT “payola_affiliates”.* FROM “payola_affiliates” WHERE (lower(code) = lower(NULL)) ORDER BY “payola_affiliates”.”id” ASC LIMIT 1 Job Load (1.0ms) SELECT “jobs”.* FROM […]

Rails ActiveJob – 在ActionMailer :: DeliveryJob中处理exception的好方法是什么

我在我的Rails项目中使用ActiveJob + Sidekiq进行任务处理。 我使用MyMailer.some.deliver_later直接发送邮件。 它将自动创建一个ActionMailer::DeliveryJob任务并将其放入Sidekiq队列中。 问题是,从那里处理exception有什么好处? 最好的祝福。

Rails – 后台作业中的ActionDispatch :: Http :: UploadedFile

我正在使用与导入csv和excel Railscast类似的想法,但由于该剧集中的标准代码需要一些时间来处理(使用ActiveRecord为文件中的每一行创建新记录)我在Heroku上获得超时并希望将导入过程移至后台作业。 我没有成功将文件变量(类型为ActionDispatch :: Http :: UploadedFile)发送到作业,所以我发送了file.original_filename和file.path的各个变量。 作业失败,错误file /var/folders/q3/xn0bp7yd2m56_4lbq0069jj80000gn/T/RackMultipart20150319-72431-1a4pnja.xlsx does not exist ,我认为这种情况正在发生,因为该文件在作业开始之前已被删除: 上传的文件是临时文件,其生命周期是一个请求。 当对象完成后,Ruby取消链接文件,因此不需要使用单独的维护任务来清除它们。 ActionDispatch :: HTTP :: UploadedFile的 使用ActionDispatch :: Http :: UploadedFile上传的文件是否可以在后台作业中使用? 我正在使用Rails 4.2,ActiveJob和Resque

使用Sidekiq进行活动作业并获取ActiveJob :: DeserializationError

我正在尝试使用Sidekiq来完成以下工作。 作业在没有排队(perform_now)时表现良好,但在调用(perform_later)时失败,后者使用Sidekiq。 AddEmployeesToRoomJob.perform_now room ## works fine AddEmployeesToRoomJob.perform_later room ## breaks in Sidekiq 错误: AddEmployeesToRoomJob JID-da24b13f405b1ece1212bbd5 INFO: fail: 0.003 sec 2016-08-20T14:57:16.645Z 19456 TID-owmym5fbk WARN: {“class”:”ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper”,”wrapped” :”AddEmployeesToRoomJob”,”queue”:”default”,”args”: [{“job_class”:”AddEmployeesToRoomJob”,”job_id”:”0ba5bd30-e281-49a7-a93f- 6e50445183ac”,”queue_name”:”default”,”priority”:null,”arguments”: [{“_aj_globalid”:”gid://dragonfly/Room/1″}],”locale”:”en”}],”retry”:true, “jid”:”da24b13f405b1ece1212bbd5″,”created_at”:1471704675.739077,”enqueued _at”:1471705036.6406531,”error_message”:”Error while trying to deserialize arguments: Couldn’t find Room with ‘id’=1″,”error_class”:”ActiveJob::DeserializationError”,”failed_at”:14717 04675.946183,”retry_count”:4,”retried_at”:1471705036.644416} 2016-08-20T14:57:16.645Z 19456 TID-owmym5fbk WARN: ActiveJob::DeserializationError: Error while trying to deserialize arguments: Couldn’t find […]

Action Job / Mailer的`deliver_now`和`deliver_later`之间的区别

在Rails中与ActionJob连接的常见模式是使用perform()方法设置Job,该方法通过perform_now或perform_later异步调用 在Mailers的特例中,您可以直接调用deliver_now或deliver_later因为ActionJob与ActionMailer很好地集成在一起。 rails文档有以下注释 – # If you want to send the email now use #deliver_now UserMailer.welcome(@user).deliver_now # If you want to send the email through Active Job use #deliver_later UserMailer.welcome(@user).deliver_later 措辞使得似乎deliver_now 不会使用ActiveJob发送邮件。 这是正确的,如果是这样, deliver_now和deliver_later之间的真正区别是什么? 一个不是异步的吗? 同样,相同的差异适用于perform_now和perform_later吗? 谢谢!

在rspec中使用ActiveJob执行挂起作业

我有这个代码用Rspec测试ActiveJob和ActionMailer我不知道如何真正执行所有排队的工作 describe ‘whatever’ do include ActiveJob::TestHelper after do clear_enqueued_jobs end it ‘should email’ do expect(enqueued_jobs.size).to eq(1) end end

在使用ActiveJob时,您是否仍然只传递对象ID?

在ActiveJob中执行以下操作的优缺点是什么: 选项A: // Controller MyJob.perform_later(object.id) // my_job.rb def perform(object_id) object = Object.find(object_id) // do stuff end 选项B: // Controller MyJob.perform_later(object) // my_job.rb def perform(object) // do stuff end

Sidekiq Rails 4.2使用活动作业还是工作者? 有什么不同

这是我第一次异步处理作业我正在我的应用程序中实现Sidekiq进行后台处理。 我会用它来提醒电子邮件和应用内通知。 我很困惑我是否应该使用Active Job创建一个发送电子邮件或Sidekiq Worker来发送电子邮件的工作。 他们似乎做同样的事情,Rails 4.2 Active Job似乎很新……它是否取代了对Sidekiq工作者的需求? 以下是使用Active Job作业和Sidekiq Worker发送邮件代码的相同内容。 我正在使用Whenever gem进行调度。 my_mailers.rb class MyMailers < ActionMailer::Base def some_mailer(r.user_id) @user = User.find(r.user_id) mailer_name = "ROUNDUP" @email = @user.email @subject ="subject text" mail(to: @email, subject: @subject, template_path: '/notifer_mailers', template_name: 'hourly_roundup.html', ) end end 使用Sidekiq“工人” some_worker.rb class SomeWorker include Sidekiq::Worker def perform() @user = User.all […]

Rails 4.2从活动作业中获得延迟的作业ID

知道如何从ActiveJob入队获取Delayed::Job id吗? 当我排队工作时,我用@job_id返回一个ActiveJob::Base的实例,但该工作ID似乎是ActiveJob的内部。 到目前为止,我最好的猜测就是走下最近创建的工作: active_job_id = GenerateReportJob.perform_later(self.id).job_id delayed_job = Delayed::Job.order(id: :desc).limit(5).detect do |job| YAML.load(job.handler).job_data[‘job_id’] == active_job_id end 但这似乎是各种各样的hacky。 有点惊讶的ActiveJob没有从Delayed::Job返回ID,特别是因为这是在作业入队时显式返回的内容。 ==编辑 看起来我不是唯一一个( https://github.com/rails/rails/issues/18821 )