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 というファイルを1つ作成しました

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

遅延ジョブ テーブルにエントリを作成する方法がわかりません。ログでも、エラーは発生していません。performメソッドで書いたタスクをrun_at時に実行するためにdelayed jobにエントリーしたい。特定の時間にタスクを実行するために、管理者から遅延ジョブにエントリを作成する別の方法はありますか。

サンプル アプリケーションの gem リスト

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>

作業アプリケーションの gem リスト

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'

gem の依存関係に問題があるのでしょうか。追跡できません。

4

0 に答える 0