jobs is not firing on heroku using hirefire - ruby-on-rails-3

i'm using gem "delayed_job_active_record" with hire fire on heroku to run jobs in background.i have also set heroku envirnoment variable using my heroku account. My sequence in gem file is below
gem 'delayed_job_active_record'
gem 'daemons'
gem 'hirefire'
it is working in local envirnoment in development as production as well. But jobs not firing on heroku from delayed job table. First i try with no config file hirefire.rb in intilizer but no succes. After i add and put this code below.
HireFire.configure do |config|
if Rails.env.production?
config.max_workers = 5 # default is 1
config.min_workers = 0 # default is 0
config.job_worker_ratio = [
{:jobs => 1, :workers => 1},
{:jobs => 15, :workers => 2},
{:jobs => 35, :workers => 3},
{:jobs => 60, :workers => 4},
{:jobs => 80, :workers => 5}
]
end
end
but no success. Although hirefire is also loading see screen shot below also

Should probably not be doing check for Rails.env.production? there and put that in config/environments/production.rb instead.
To see how to setup delayed_job_active_record in Heroku, read this: https://devcenter.heroku.com/articles/delayed-job

Related

Paperclip::Errors::NotIdentifiedByImageMagickError + Heroku

I currently have an application using paperclip that allows users to upload their creatives. This has worked flawless thus far when it comes to a user uploading an image file. We have since tested to upload a .mov file and I get this error:
Creative Paperclip::Errors::NotIdentifiedByImageMagickError
The weird thing, this error is only generated on Heroku. I can upload .mov files just fine on my local host.
My Current Gem Setup:
paperclip (3.4.1, 3.4.0)
paperclip-aws (1.6.7, 1.6.6)
paperclip-ffmpeg (0.10.2)
cocaine (0.5.1, 0.4.2)
Event.rb
has_attached_file :creative,
:processors => [:ffmpeg],
:styles => {
:thumb => [:geometry => "250x150", :format => 'png'],
:custcreative => [:geometry => "275x75", :format => 'png'],
:creativepreview => ["275x195",:png]
},
:url => "***",
:path => "***",
:s3_domain_url => "***",
:storage => :s3,
:s3_credentials => Rails.root.join("config/s3.yml"),
:bucket => '***',
:s3_permissions => :public_read,
:s3_protocol => "http",
:convert_options => { :all => "-auto-orient" },
:encode => 'utf8'
Spending hours trying to figure out why this works locally but throwing error on Heroku.
I even tried removing the :style setting, but still did not work.
TIA
EDIT
Command :: identify -format '%wx%h,%[exif:orientation]' '/tmp/MidPen20130413-2-1mzetus.mov[0]'
Well, here is the answer in case any other newbies like us come across the same problem. The issue is with the geometry method that is being used for image cropping. The way it is suggested in railscasts assumes the file is in a local system and that needs to be changed.
OLD METHOD:
def avatar_geometry(style = :original)
#geometry ||= {}
#geometry[style] ||= Paperclip::Geometry.from_file(avatar.path(style))
end
NEW METHOD
def avatar_geometry(style = :original)
#geometry ||= {}
avatar_path = (avatar.options[:storage] == :s3) ? avatar.url(style) : avatar.path(style)
#geometry[style] ||= Paperclip::Geometry.from_file(avatar_path)
end

rails generator does not create rspec file/directory in rails 3.2.9 engine

We create rails 3.2.9 engine with the command below:
rails plugin new my_eng --mountable --dummy-path=spec/dummy
in my_eng.gemspec, rspec was added:
s.add_development_dependency "rspec-rails", ">= 2.0.0"
Run bundle install. Then in engine's root directory:
rails g rspec:install
A spec_helper.rb file is created under spec/.
The problem is that when a model or controller is created,ex, rails g model my_model..., under spec/, there is no models directory and my_model_spec.rb were created. We tried to run rails g rspec:install under spec/dummy/ and the problem remains. What's wrong with our code? Thanks for the help.
You gotta insert in config/application.rb something like:
config.generators do |g|
g.template_engine :erb
g.test_framework :rspec, :fixture => true, :views => false
g.integration_tool :rspec, :fixture => true, :views => true
g.fixture_replacement :factory_girl, :dir => "spec/support/factories"
end

How do I configure WEBrick to use an intermediate certificate with HTTPS?

I am currently using the following options in my Rails app to enable HTTPS with WEBrick:
{
:Port => 3000,
:environment => (ENV['RAILS_ENV'] || "development").dup,
:daemonize => false,
:debugger => false,
:pid => File.expand_path("tmp/pids/server.pid"),
:config => File.expand_path("config.ru"),
:SSLEnable => true,
:SSLVerifyClient => OpenSSL::SSL::VERIFY_NONE,
:SSLPrivateKey => OpenSSL::PKey::RSA.new(
File.open("certificates/https/key.pem").read),
:SSLCertificate => OpenSSL::X509::Certificate.new(
File.open("certificates/https/cert.pem").read),
:SSLCertName => [["CN", WEBrick::Utils::getservername]]
}
How would I go about specifying an intermediate certificate?
I managed to find an answer after an extra hour of googling for keywords. Here is the option to define an intermediate certificate:
:SSLExtraChainCert => [
OpenSSL::X509::Certificate.new(
File.open("certificates/intermediate.crt").read)]
Note that the option requires an Array object, allowing to you include multiple certificates if needed.
If you are using rails 3, then modify the script/rails file as
#!/usr/bin/env ruby
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
require 'rubygems' # if ruby 1.8.7
require 'rails/commands/server'
require 'rack'
require 'webrick'
require 'webrick/https'
module Rails
class Server < ::Rack::Server
def default_options
super.merge({
:Port => 3000,
:environment => (ENV['RAILS_ENV'] || "development").dup,
:daemonize => false,
:debugger => false,
:pid => File.expand_path("tmp/pids/server.pid"),
:config => File.expand_path("config.ru"),
:SSLEnable => true,
:SSLVerifyClient => OpenSSL::SSL::VERIFY_NONE,
:SSLPrivateKey => OpenSSL::PKey::RSA.new(
File.open("/key/vhost1.key").read),
:SSLCertificate => OpenSSL::X509::Certificate.new(
File.open("/crt/vhost1.crt").read),
:SSLCertName => [["CN", WEBrick::Utils::getservername]],
})
end
end
end
APP_PATH = File.expand_path('../../config/application', __FILE__)
require File.expand_path('../../config/boot', __FILE__)
require 'rails/commands'
The above code was modified from the example in Configuring WEBrick to use SSL in Rails 3. This worked for me.

migrated rails3 app to heroku, now paperclip+s3 not uploading files - nothing in heroku logs

Hi I just migrated to heroku cedar stack. app is Rails 3, ive been using paperclip on s3 just fine previously. my gemfile has:
gem 'paperclip', '2.3.11'
gem 'aws-s3', '0.6.2'
my model file has:
class UserProfile < ActiveRecord::Base
has_attached_file :avatar,
:styles => { :thumb => "150x200#" },
:default_style => :thumb,
:default_url => "missingAvatar.png",
:storage => :s3,
:s3_credentials => S3_CREDENTIALS
Ive created a new file to store S3_CREDENTIALS,:
# initializers/s3.rb
if Rails.env == "production"
# set credentials from ENV hash
S3_CREDENTIALS = { :access_key_id => ENV['S3_KEY'], :secret_access_key => ENV['S3_SECRET'], :bucket => "app_content"}
else
# get credentials from YML file
S3_CREDENTIALS = Rails.root.join("config/s3.yml")
end
... with s3.yml containing my keys for local dev, and the keys set in heroku config:
S3_KEY => AK...
S3_SECRET => FFE...
as mentioned, everything works just fine on local. i can even see the existing avatars from before. just, when i try to upload anything new, i get no errors in heroku logs, but the picture never uploads.
ive went thru many stackoverflow issues, but none matching this. can anyone help??
Try adding the following to your model
class UserProfile < ActiveRecord::Base
has_attached_file :avatar,
:styles => { :thumb => "150x200#" },
:default_style => :thumb,
:default_url => "missingAvatar.png",
:storage => :s3,
:s3_credentials => S3_CREDENTIALS,
:url => "/assets/avatar/:id/:style/:basename.:extension",
:path => ":rails_root/public/assets/avatar/:id/:style/:basename.:extension"
The missing path / default path might be causing an issue.
turns out i needed to upgrade my paperclip gem to '2.4.5'
i did this in my Gemfile, then bundle update, and it worked!

Using Rails 3 gem Manifesto

I am trying to use the HTML5 manifest function using a gem called Manifesto. I am stuck on the instructions for usage. I cannot figure out where those settings are supposed to go.
Any ideas? Perhaps a better gem?
https://github.com/johntopley/manifesto#readme
Thankful for all help!
You can put you settings in a file under config/initializers/. Use an informational name (like manifesto.rb). However you don't need a config with the basic usage.
In your Gemfile file, add:
gem 'manifesto'
then install via bundle:
bundle install
create the file app/controllers/manifest_controller.rb
class ManifestController < ApplicationController
def show
headers['Content-Type'] = 'text/cache-manifest'
render :text => Manifesto.cache, :layout => false
end
end
in config/routes.rb add:
match '/manifest' => 'manifest#show'
Restart your app and view the result at http://localhost:3000/manifest
You can pass the option directly to Manifesto.cache like:
# change
render :text => Manifesto.cache, :layout => false
# to
render :text => Manifesto.cache(:directory => './mobile', :compute_hash => false), :layout => false
Or use a YAML file and an initializer.
The config/manifesto.yaml file:
# directory is relative to Rails root
directory: './mobile'
compute_hash: false
The config/initializers/manifesto.rb file:
# Load the config file and convert keys from strings in symbols (the manifesto gem need symbolized options).
MANIFESTO_CONFIG = YAML.load_file(Rails.root.join('config', 'manifesto.yml').to_s).inject({}){|config,(k,v)| config[k.to_sym] = v; config}
And pass the loaded config to Manifesto.cache like:
# change
render :text => Manifesto.cache, :layout => false
# to
render :text => Manifesto.cache(MANIFESTO_CONFIG), :layout => false