From active admin after create of any record.
In model i have called callback method: 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
But it is not making any entry in delayed job table and directly executing perform method
In lib i have created one file called 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
I am not getting how can i make entry in delayed jobs table. In log also i am not getting any error.
I want to make entry in delayed job to run the task written in perform method at run_at time.
Is their any alternate way from admin we cam make entry in delayed job to run the task at specific time.
sample application gem list
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'
For sample application I am able to make entry in delayed job:
Below í is the console output
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 >
But the application in which I am working on from the console I am getting something different output. Below is the sample output.
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>
Working application gem list
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'
Is it problem with the gem dependences, I am not able to track it out.
I am using WickedPDF, and I have basically two gems that include the binaries:
gem "wkhtmltopdf-heroku", "1.0.0"
gem "wkhtmltopdf-binary", "0.9.5.3"
The first one is supposed to be just for production, and the second one for development. The deployment to Heroku doesn't work if I have my Gemfile like:
group :development do
gem "wkhtmltopdf-binary", "0.9.5.3"
end
group :production do
gem "wkhtmltopdf-heroku", "1.0.0"
end
And it doesn't work either if I have it like:
group :production do
gem "wkhtmltopdf-heroku", "1.0.0"
end
It just works if I have it without groups. Just like:
gem "wkhtmltopdf-heroku", "1.0.0"
The error that I get is:
RuntimeError: Location of wkhtmltopdf unknown
Why would this happen? Why Heroku is not using the production group?
WickedPdf tries to figure out where the wkhtmltopdf binary lives, but can have a hard time on some systems (particularly shared servers).
You probably have to set it manually in an initializer something like this:
bin_location = case Rails.env
when 'production' then "/wherever/your/binary/is/bin/wkhtmltopdf"
when 'development' then "/local/path/to/wkthmltopdf"
else `which wkhtmltopdf`
end
WickedPdf.config = { :exe_path => bin_location }
I am running RAILS 3.0.9, and for the life of me, I can not get RAILS to do the new lazy loading.
My gemfile is:
gem 'rails', '3.0.9'
gem 'sqlite3'
gem 'nifty-generators', '>= 0.4.6'
gem 'mocha', :group => :test
gem 'carrierwave'
gem 'rmagick'
gem 'devise', '1.1.rc0'
gem 'jquery-rails', '>= 1.0.3'
And if I do:
Period.where("id=1")
I get:
[#<Period id: 1, start: "2011-07-06", end: "2011-07-13", created_at: "2011-07-06 23:01:46", updated_at: "2011-07-06 23:01:46"]
I really need it to do the ActiveRecord::Relation thing instead! Anyone know what's going on?
You are doing the ActiveRecord::Relation thing.
foo = Period.where("id=1") # does AR::Relation thing
foo.select( :start ) # does AR::Relation thing
p foo.to_a # Does SQL cmd thing cuz u forced AR::Relation thing to SQL
You should only see your start column reported.
An ActiveRecord::Relation doesn't evaluate until forced to... like you want it to print values.
I'm trying to deploy a simple skeleton Rails 3.0.5 (and Ruby 1.9.2) app to Heroku, but encounter the same error when I open the website and when I try to migrate the db. I created the Heroku app with heroku create --stack bamboo-mri-1.9.2. Everything works locally.
Code: https://github.com/curiousyogurt/SEE
App: http://stormy-ice-778.heroku.com/
When going to the website, I get an "Application Error"; in the logs, I get the following error (followed by lots of other information):
2011-03-20T17:25:31-07:00 app[web.1]: /app/cfde9dd3-c394-45fb-a0ef-72a753e83909/home/.bundle/gems/ruby/1.9.1/gems/railties-3.0.5/lib/rails/railtie/configuration.rb:77:in 'method_missing': undefined method `action' for #<Rails::Application::Configuration:0x00000001d398d8> (NoMethodError)
Stack Trace: gist.github.com/878866
When doing heroku rake db:migrate, I get the following error:
rake aborted!
undefined method 'action' for #
/app/44666f97-ad08-444e-9f39-9ca7eb8fdc93/home/.bundle/gems/ruby/1.9.1/gems/railties-3.0.5/lib/rails/railtie/configuration.rb:77:in `method_missing'
Stack Trace: gist.github.com/878870
Here is my Gemfile (non-production parts removed):
gem 'rails', '3.0.5'
gem 'haml'
gem 'devise', :git => 'git://github.com/plataformatec/devise',
:branch => 'master'
gem 'omniauth'
I'm not sure where to go next in trying to track down this problem. Any suggestions would be greatly appreciated.
config.action.mailer.default_url_options = { :host => 'stormy-ice-778.heroku.com' }
in your config/environments/production.rb should be
config.action_mailer.default_url_options = { :host => 'stormy-ice-778.heroku.com' }
(change action.mailer to action_mailer).
gem 'rails', '3.0.0'
gem 'devise'
gem 'bson_ext', '>= 1.0.7'
gem 'bson', '>= 1.0.7'
gem 'mongo_mapper', :branch => 'rails3', :git => 'http://github.com/jnunemaker/mongomapper.git'
gem 'devise-mongo_mapper', :git => 'git://github.com/collectiveidea/devise-mongo_mapper'
With the above setup I get the following errors on requests:
Started GET "/users/sign_out" for 127.0.0.1 at 2010-09-27 13:16:30 +0300
Processing by Devise::SessionsController#destroy as HTML
Redirected to http://localhost:3000/
Completed 302 Found in 19ms
[2010-09-27 13:16:31] ERROR Errno::ECONNRESET: Connection reset by peer
/usr/local/ruby/lib/ruby/1.9.1/webrick/httpserver.rb:56:in `eof?'
/usr/local/ruby/lib/ruby/1.9.1/webrick/httpserver.rb:56:in `run'
/usr/local/ruby/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
Started GET "/users/edit" for 127.0.0.1 at 2010-09-27 13:16:35 +0300
Processing by Devise::RegistrationsController#edit as HTML
Completed in 16ms
[2010-09-27 13:16:35] ERROR Errno::ECONNRESET: Connection reset by peer
/usr/local/ruby/lib/ruby/1.9.1/webrick/httpserver.rb:56:in `eof?'
/usr/local/ruby/lib/ruby/1.9.1/webrick/httpserver.rb:56:in `run'
/usr/local/ruby/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
The user model:
class User
include MongoMapper::Document
plugin MongoMapper::Devise
devise :registerable, :database_authenticatable, :recoverable
end
Ideas?
WebRick has been replaced with Thin.
Doing the following worked for me:
Gemfile:
gem 'thin'
Now do bundle install
My quick guess is this looks like you have a problem with your sessions and protect_from_forgery is kicking in.
I had a similar problem and smashed my head against the wall for a few days, it turned out to be I was assigning an entire object to a session object instead of just the id. A quick note, non-GET requests are the ones that trigger the protect_from_forgery.
Adding this to my development.rb file fixed the issue.
config.assets.raise_runtime_errors = true
config.web_console.whitelisted_ips = replace_this_with_the_public_ip