2

在创建任何记录后从活动管理员。

在模型中我调用了回调方法: after_save :check_delayed_job

def check_delayed_job
 run_at_time = Time.now.utc + 50
 Delayed::Job.enqueue(AdminNewsletterRequest.new('example@gmail.com', 'sample     newsletter content'), :priority => 3 , :run_at => run_at_time)  
end  

但它没有在延迟作业表中创建任何条目并直接执行执行方法在 lib 中我创建了一个名为 admin_newsletter_request.rb 的文件

class AdminNewsletterRequest < Struct.new(:email, :subject)
  def perform
    UserMailer.sample_letter(email, subject).deliver
    puts " weekly mail delivered succussfully! "           
  end   
end

我不知道如何在延迟作业表中进行条目。在日志中我也没有收到任何错误。我想进入延迟作业以在 run_at 时间运行用 perform 方法编写的任务。他们是否可以从管理员那里获得任何替代方式,我们可以在延迟的工作中进入以在特定时间运行任务。

示例应用程序宝石列表

source 'https://rubygems.org'

gem 'rails', '~> 3.2.0'
gem 'pg'
gem 'daemons'
gem 'delayed_job_active_record'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'sqlite3'


# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  gem 'therubyracer', :platforms => :ruby

  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# To use Jbuilder templates for JSON
# gem 'jbuilder'

# Use unicorn as the app server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
# gem 'debugger'

对于示例应用程序,我可以在延迟工作中进行输入: 下面是控制台输出

1.9.2-p290 :002 > Delayed::Job.enqueue(AdminNewsletterRequest.new('example@gmail.com', 'sample newsletter content'), :priority => 3 , :run_at => run_at_time)
   (0.4ms)  BEGIN
  SQL (103.4ms)  INSERT INTO "delayed_jobs" ("attempts", "created_at", "failed_at", "handler", "last_error", "locked_at", "locked_by", "priority", "queue", "run_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11) RETURNING "id"  [["attempts", 0], ["created_at", Thu, 13 Dec 2012 07:27:49 UTC +00:00], ["failed_at", nil], ["handler", "--- !ruby/struct:AdminNewsletterRequest \nemail: example@gmail.com\nsubject: sample newsletter content\n"], ["last_error", nil], ["locked_at", nil], ["locked_by", nil], ["priority", 3], ["queue", nil], ["run_at", Thu, 13 Dec 2012 07:28:22 UTC +00:00], ["updated_at", Thu, 13 Dec 2012 07:27:49 UTC +00:00]]
   (13.6ms)  COMMIT
 => #<Delayed::Backend::ActiveRecord::Job id: 9, priority: 3, attempts: 0, handler: "--- !ruby/struct:AdminNewsletterRequest \nemail: san...", last_error: nil, run_at: "2012-12-13 07:28:22", locked_at: nil, failed_at: nil, locked_by: nil, queue: nil, created_at: "2012-12-13 07:27:49", updated_at: "2012-12-13 07:27:49"> 
1.9.2-p290 :003 > 

但是我从控制台处理的应用程序得到了不同的输出。下面是示例输出。

Delayed::Job.enqueue(AdminNewsletterRequest.new('example@gmail.com', 'sample newsletter content'), :priority => 3 , :run_at => run_at_time)
 weekly mail delivered succussfully! 
=> #<Delayed::Backend::ActiveRecord::Job id: nil, priority: 0, attempts: 0, handler: "--- !ruby/struct:AdminNewsletterRequest \nemail: san...", last_error: nil, run_at: nil, locked_at: nil, failed_at: nil, locked_by: nil, queue: nil, created_at: nil, updated_at: nil>

工作应用程序宝石列表

source 'http://rubygems.org'

gem 'rails', '~> 3.2.0'

gem 'pg'

# Gem used by scap:
# To minimize merge conflicts, keep this list sorted alphabetically
gem 'activeadmin', '>= 0.5'
gem 'airbrake'
gem 'braintree'
gem 'compass', '~> 0.12.alpha.0'
gem 'context-io', git: 'https://github.com/henrikhodne/context-io.git'
gem 'covenant'
gem 'delayed_job_active_record'
gem 'devise', '~> 2.0.0'
gem 'dragonfly'
gem 'fog'
gem 'foreigner'
gem 'formtastic', '~> 2.2.1'
gem 'friendly_id'
gem 'geocoder'
gem 'gmaps4rails'
gem 'haml', '~> 3.1'
gem 'has_scope'
gem 'hashie'
gem 'httparty'
gem 'i18n-js'
gem 'jquery-rails'
gem 'js-routes'
gem 'kaminari'
gem 'meta_search', '>= 1.1.0.pre'
gem 'newrelic_rpm'
gem 'omniauth'
gem 'omniauth-google-oauth2'
gem 'pry-rails'
gem 'rdiscount'
gem 'seed-fu'
gem 'simple-navigation'
gem 'thin'
gem 'uuidtools'
gem 'valid_email', require: 'valid_email/email_validator'
gem 'valium'
gem 'yipit_n4l', require: 'yipit', git: 'git://github.com/Nest4LessDev/yipit.git'
#gem 'bootstrap-colorpicker-rails', :require => 'bootstrap-colorpicker-rails',
                          #:git => 'git://github.com/alessani/bootstrap-colorpicker-rails.git'
gem 'jquery-minicolors-rails'
gem 'therubyracer'
gem 'jquery-timepicker-rails'

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails'
  gem 'coffee-rails'
  gem 'uglifier', '>= 1.0.3'
  gem 'haml_coffee_assets'
end

group :test do
  gem 'cucumber-rails', require: false
  gem 'database_cleaner'
  gem 'email_spec'
  gem 'factory_girl_rails'
  gem 'capybara'
  gem 'rr'
  gem 'shoulda-matchers'
  gem 'valid_attribute'
  gem "shoulda-matchers"
  gem 'fake_braintree', require: false
end

group :development, :test do
  gem 'launchy'
  gem 'rspec-rails'
  gem 'awesome_print', :require => 'ap'  # pretty print objects in console via `ap my_object`
end

gem 'pry'

宝石依赖性是否有问题,我无法追踪它。

4

0 回答 0