Solution:
Added the following to the bottom of deploy.rb
Rake::Task["deploy:assets:restore_manifest"].clear_actions
before 'deploy:finishing_rollback', 'deploy:pre_start_precompile'
task :pre_start_precompile do
on roles(:db) do
with rails_env: "#{fetch(:stage)}" do
path_to_bundler = "/usr/local/rbenv/shims/bundle"
execute "cd #{release_path}; RAILS_ENV=production #{path_to_bundler} exec rake assets:precompile"
end
end
end
This worked!
Original question:
I'm running Rails 4.2 and Ruby 2.5.8 and capistrano 3.14.1. When I try and roll back I get this error;
** Execute bundler:install
00:04 bundler:install
The Gemfile's dependencies are satisfied, skipping installation
** Execute deploy:reverted
** Invoke deploy:rollback_assets (first_time)
** Invoke deploy:set_rails_env
** Execute deploy:rollback_assets
** Invoke deploy:assets:restore_manifest (first_time)
** Execute deploy:assets:restore_manifest
00:04 deploy:assets:restore_manifest
WARN Rails assets manifest file (or backup file) not found.
#<Thread:0x00007ff7f8218548#/home/map7/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:10 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /home/map7/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute'
/home/map7/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute': Exception while executing as user#<server ip>: Rails assets manifest file (or backup file) not found. (SSHKit::Runner::ExecuteError)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as <user>#<server ip>: Rails assets manifest file (or backup file) not found.
/home/map7/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute'
/home/map7/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute'
Caused by:
Capistrano::FileNotFound: Rails assets manifest file (or backup file) not found.
/home/map7/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/capistrano-rails-1.6.1/lib/capistrano/tasks/assets.rake:103:in `block (5 levels) in <top (required)>'
/home/map7/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/sshkit-1.21.0/lib/sshkit/backends/abstract.rb:92:in `within'
/home/map7/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/capistrano-rails-1.6.1/lib/capistrano/tasks/assets.rake:90:in `block (4 levels) in <top (required)>'
/home/map7/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/sshkit-1.21.0/lib/sshkit/backends/abstract.rb:31:in `instance_exec'
/home/map7/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/sshkit-1.21.0/lib/sshkit/backends/abstract.rb:31:in `run'
/home/map7/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
Tasks: TOP => deploy:assets:restore_manifest
I read somewhere that I have to make two files on the production server which I have and it didn't make a difference;
$ touch public/assets/.manifest.json
$ touch public/assets/.sprockets-manifest.json
The error happens within assets.rake part of capistrano-rails;
task :restore_manifest do
on release_roles(fetch(:assets_roles)) do
within release_path do
targets = detect_manifest_path.split(' ')
sources = targets.map do |target|
release_path.join('assets_manifest_backup', File.basename(target))
end
if test(:ls, *sources) && test(:ls, *targets) # <-- this line
source_map = sources.zip(targets)
source_map.each do |source, target|
execute :cp, source, target
end
else
msg = 'Rails assets manifest file (or backup file) not found.'
warn msg
fail Capistrano::FileNotFound, msg
end
end
end
end
I manually tested sources and targets. I found sources failed and targets passed. Below are both;
(byebug) sources
[#<Pathname:/var/www/<site>.com.au/releases/20201004053756/assets_manifest_backup/.sprockets-manifest-2df820954d56273c97d9696e88075409.json>, #<Pathname:/var/www/<site>.com.au/releases/20201004053756/assets_manifest_backup/.sprockets-manifest.json>]
(byebug) targets
["/var/www/<site>.com.au/releases/20201004053756/public/assets/.sprockets-manifest-2df820954d56273c97d9696e88075409.json", "/var/www/<site>.com.au/releases/20201004053756/public/assets/.sprockets-manifest.json"]
Update: listing of shared/public
[capistrano root]/shared/public$ find .
.
./system
./assets
./assets/application-e02d56bdf7493178ee13a95f4211508873eedfc4dbcff55cda9447e26b589ad0.js
./assets/application-04fbdaf9d6b9abbae40cd5dbc0a71ca7094b363cf5016d06db76b7018a397231.css
./assets/application-04fbdaf9d6b9abbae40cd5dbc0a71ca7094b363cf5016d06db76b7018a397231.css.gz
./assets/.sprockets-manifest-2df820954d56273c97d9696e88075409.json
./assets/application-81e70a4729ca29787e86c6981d9275dedbedddab40a87dfbcc39e19c9851c7b6.css
./assets/application-89cedfcf3e9592cd9f252337803bc10a9e57d40dc7fa8e192f2a4a32ef109b0c.js.gz
./assets/application-89cedfcf3e9592cd9f252337803bc10a9e57d40dc7fa8e192f2a4a32ef109b0c.js
./assets/application-e02d56bdf7493178ee13a95f4211508873eedfc4dbcff55cda9447e26b589ad0.js.gz
./assets/application-9416e76266dcf39961fba3ae76d96e7e89ce9e0eba1a0ccf529aa003869cac9d.css
./assets/.manifest.json
./assets/.sprockets-manifest.json
./assets/application-9416e76266dcf39961fba3ae76d96e7e89ce9e0eba1a0ccf529aa003869cac9d.css.gz
./assets/application-81e70a4729ca29787e86c6981d9275dedbedddab40a87dfbcc39e19c9851c7b6.css.gz
Related
When I run bundle exec rake db:setup I get an error saying that rake doesn't know how to build that task. I then run bundle exec rake -T and see that db tasks are missing (all output below). How can I access the db tasks?
--application.rb--
require File.expand_path('../boot', __FILE__)
require 'rails'
require 'active_model/railtie'
require 'active_job/railtie'
require 'action_controller/railtie'
require 'action_view/railtie'
require 'sprockets/railtie'
Bundler.require(*Rails.groups)
module LofocatsUi
class Application < Rails::Application
end
end
--rake command--
bos-mp478:lofocats_ui rabdelaz$ bundle exec rake db:setup --trace
rake aborted!
Don't know how to build task 'db:setup' (See the list of available tasks with `rake --tasks`)
/Users/rabdelaz/.rvm/gems/ruby-2.4.3#lofocats-ui/gems/rake-12.3.2/lib/rake/task_manager.rb:59:in `[]'
/Users/rabdelaz/.rvm/gems/ruby-2.4.3#lofocats-ui/gems/rake-12.3.2/lib/rake/application.rb:159:in `invoke_task'
/Users/rabdelaz/.rvm/gems/ruby-2.4.3#lofocats-ui/gems/rake-12.3.2/lib/rake/application.rb:116:in `block (2 levels) in top_level'
/Users/rabdelaz/.rvm/gems/ruby-2.4.3#lofocats-ui/gems/rake-12.3.2/lib/rake/application.rb:116:in `each'
/Users/rabdelaz/.rvm/gems/ruby-2.4.3#lofocats-ui/gems/rake-12.3.2/lib/rake/application.rb:116:in `block in top_level'
/Users/rabdelaz/.rvm/gems/ruby-2.4.3#lofocats-ui/gems/rake-12.3.2/lib/rake/application.rb:125:in `run_with_threads'
/Users/rabdelaz/.rvm/gems/ruby-2.4.3#lofocats-ui/gems/rake-12.3.2/lib/rake/application.rb:110:in `top_level'
/Users/rabdelaz/.rvm/gems/ruby-2.4.3#lofocats-ui/gems/rake-12.3.2/lib/rake/application.rb:83:in `block in run'
/Users/rabdelaz/.rvm/gems/ruby-2.4.3#lofocats-ui/gems/rake-12.3.2/lib/rake/application.rb:186:in `standard_exception_handling'
/Users/rabdelaz/.rvm/gems/ruby-2.4.3#lofocats-ui/gems/rake-12.3.2/lib/rake/application.rb:80:in `run'
/Users/rabdelaz/.rvm/gems/ruby-2.4.3#lofocats-ui/gems/rake-12.3.2/exe/rake:27:in `<top (required)>'
/Users/rabdelaz/.rvm/gems/ruby-2.4.3#lofocats-ui/bin/rake:23:in `load'
/Users/rabdelaz/.rvm/gems/ruby-2.4.3#lofocats-ui/bin/rake:23:in `<top (required)>'
/Users/rabdelaz/.rvm/rubies/ruby-2.4.3/lib/ruby/site_ruby/2.4.0/bundler/cli/exec.rb:74:in `load'
/Users/rabdelaz/.rvm/rubies/ruby-2.4.3/lib/ruby/site_ruby/2.4.0/bundler/cli/exec.rb:74:in `kernel_load'
/Users/rabdelaz/.rvm/rubies/ruby-2.4.3/lib/ruby/site_ruby/2.4.0/bundler/cli/exec.rb:28:in `run'
/Users/rabdelaz/.rvm/rubies/ruby-2.4.3/lib/ruby/site_ruby/2.4.0/bundler/cli.rb:424:in `exec'
/Users/rabdelaz/.rvm/rubies/ruby-2.4.3/lib/ruby/site_ruby/2.4.0/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/Users/rabdelaz/.rvm/rubies/ruby-2.4.3/lib/ruby/site_ruby/2.4.0/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
/Users/rabdelaz/.rvm/rubies/ruby-2.4.3/lib/ruby/site_ruby/2.4.0/bundler/vendor/thor/lib/thor.rb:387:in `dispatch'
/Users/rabdelaz/.rvm/rubies/ruby-2.4.3/lib/ruby/site_ruby/2.4.0/bundler/cli.rb:27:in `dispatch'
/Users/rabdelaz/.rvm/rubies/ruby-2.4.3/lib/ruby/site_ruby/2.4.0/bundler/vendor/thor/lib/thor/base.rb:466:in `start'
/Users/rabdelaz/.rvm/rubies/ruby-2.4.3/lib/ruby/site_ruby/2.4.0/bundler/cli.rb:18:in `start'
/Users/rabdelaz/.rvm/rubies/ruby-2.4.3/bin/bundle:30:in `block in <main>'
/Users/rabdelaz/.rvm/rubies/ruby-2.4.3/lib/ruby/site_ruby/2.4.0/bundler/friendly_errors.rb:124:in `with_friendly_errors'
/Users/rabdelaz/.rvm/rubies/ruby-2.4.3/bin/bundle:22:in `<main>'
/Users/rabdelaz/.rvm/gems/ruby-2.4.3#global/bin/ruby_executable_hooks:24:in `eval'
/Users/rabdelaz/.rvm/gems/ruby-2.4.3#global/bin/ruby_executable_hooks:24:in `<main>'
--tasks list--
bos-mp478:lofocats_ui rabdelaz$ bundle exec rake -T
rake about # List versions of all Rails frameworks and the environment
rake assets:clean[keep] # Remove old compiled assets
rake assets:clobber # Remove compiled assets
rake assets:environment # Load asset compile environment
rake assets:precompile # Compile all the assets named in config.assets.precompile
rake cache_digests:dependencies # Lookup first-level dependencies for TEMPLATE (like messages/show or comments/_comment.html)
rake cache_digests:nested_dependencies # Lookup nested dependencies for TEMPLATE (like messages/show or comments/_comment.html)
rake doc:app # Generate docs for the app -- also available doc:rails, doc:guides (options: TEMPLATE=/rdoc-template.rb, TITLE="Custom Title")
rake log:clear # Truncates all *.log files in log/ to zero bytes (specify which logs with LOGS=test,development)
rake middleware # Prints out your Rack middleware stack
rake notes # Enumerate all annotations (use notes:optimize, :fixme, :todo for focus)
rake notes:custom # Enumerate a custom annotation, specify with ANNOTATION=CUSTOM
rake rails:template # Applies the template supplied by LOCATION=(/path/to/template) or URL
rake rails:update # Update configs and some other initially generated files (or use just update:configs or update:bin)
rake routes # Print out all defined routes in match order, with names
rake secret # Generate a cryptographically secure secret key (this is typically used to generate a secret for cookie sessions)
rake stats # Report code statistics (KLOCs, etc) from the application or engine
rake time:zones:all # Displays all time zones, also available: time:zones:us, time:zones:local -- filter with OFFSET parameter, e.g., OFFSET=-6
rake tmp:clear # Clear session, cache, and socket files from tmp/ (narrow w/ tmp:sessions:clear, tmp:cache:clear, tmp:sockets:clear)
rake tmp:create # Creates tmp directories for sessions, cache, sockets, and pids
I created a rake task for import a csv with smarter_csv gem.
Throws the following message, i added the entire error code if it helps:
rake import_csv:import_csv
Digest::Digest is deprecated; use Digest
I, [2017-03-01T11:46:08.551994 #7029] INFO -- : ** [Raven] Raven 0.14.0 configured not to send errors.
rake aborted!
NoMethodError: undefined method `close' for nil:NilClass
/home/my_user/.rvm/gems/ruby-2.1.1#my_app/gems/smarter_csv-1.1.4/lib/smarter_csv/smarter_csv.rb:223:in `ensure in process'
/home/my_user/.rvm/gems/ruby-2.1.1#my_app/gems/smarter_csv-1.1.4/lib/smarter_csv/smarter_csv.rb:223:in `process'
/home/my_user/my_app/lib/tasks/import_csv.rake:7:in `block (2 levels) in <top (required)>'
/home/my_user/.rvm/gems/ruby-2.1.1#my_app/bin/ruby_executable_hooks:15:in `eval'
/home/my_user/.rvm/gems/ruby-2.1.1#my_app/bin/ruby_executable_hooks:15:in `<main>'
Errno::ENOENT: No such file or directory # rb_sysopen - /csv_imports/pacientes.csv
/home/my_user/.rvm/gems/ruby-2.1.1#my_app/gems/smarter_csv-1.1.4/lib/smarter_csv/smarter_csv.rb:23:in `initialize'
/home/my_user/.rvm/gems/ruby-2.1.1#my_app/gems/smarter_csv-1.1.4/lib/smarter_csv/smarter_csv.rb:23:in `open'
/home/my_user/.rvm/gems/ruby-2.1.1#my_app/gems/smarter_csv-1.1.4/lib/smarter_csv/smarter_csv.rb:23:in `process'
/home/my_user/my_app/lib/tasks/import_csv.rake:7:in `block (2 levels) in <top (required)>'
/home/my_user/.rvm/gems/ruby-2.1.1#my_app/bin/ruby_executable_hooks:15:in `eval'
/home/my_user/.rvm/gems/ruby-2.1.1#my_app/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => import_csv:import_csv
(See full trace by running task with --trace)
This is the code on the rake task:
namespace :import_csv do
desc "import csv file"
task import_csv: :environment do
require 'smarter_csv'
filename = '/csv_imports/file.csv'
options = {:key_mapping => { :downcase_header => true }}
SmarterCSV.process(filename, options) do |array|
CsvImports.create( array.first )
end
end
end
This solved just witha dot. route issue.
./csv_imports/file.csv
Some of my rSpec tests are failing and I suspect it's due to the test database not being cleared out. When I try to run rake db:test:prepare, I'm getting the error below (i'm in Rails 3.2). Clearly, this looks like some kind of Postgres issue, looks like the rake task is trying to drop the test database so it can repopulate it. Production database schema loads fine.
I've looked for the rake task in lib/tasks/ but I haven't been able to find it. Anyone have any idea on what's going on?
osx_user-> rake db:test:prepare
[RailsAdmin] RailsAdmin initialization disabled by default. Pass SKIP_RAILS_ADMIN_INITIALIZER=false if you need it.
rake aborted!
ActiveRecord::StatementInvalid: PG::SyntaxError: ERROR: zero-length delimited identifier at or near """"
LINE 1: DROP DATABASE IF EXISTS ""
^
: DROP DATABASE IF EXISTS ""
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/connection_adapters/postgresql_adapter.rb:650:in `async_exec'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/connection_adapters/postgresql_adapter.rb:650:in `block in execute'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activesupport-3.2.14/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/connection_adapters/postgresql_adapter.rb:649:in `execute'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/connection_adapters/postgresql_adapter.rb:772:in `drop_database'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/railties/databases.rake:623:in `drop_database'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/railties/databases.rake:532:in `block (3 levels) in <top (required)>'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/gems/activerecord-3.2.14/lib/active_record/railties/databases.rake:559:in `block (3 levels) in <top (required)>'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/bin/ruby_executable_hooks:15:in `eval'
/Users/osx_user/.rvm/gems/ruby-1.9.3-p547/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => db:test:load => db:test:purge
(See full trace by running task with --trace)
Figured it out. My database.yml file for the development environment was set like this:
database: <%= ENV['DATABASE_NAME_TEST'] %>
The rake task was looking for an environmental variable that did not exist.
In a Rails 4 app, I want precompiled assets to have copies of some assets to be available with a non fingerprinted filename. The app is deployed on Heroku.
I have the following rake task in place:
namespace :app do
task :nonfingerprint_assets => :environment do
manifests = Rails.application.config.assets[:precompile]
manifests = manifests.slice(1, manifests.length)
assets = Dir.glob(File.join(Rails.root, 'public/assets/**/*'))
regex = /(-{1}[a-z0-9]{32}*\.{1}){1}/
assets.each do |file|
next if File.directory?(file) || file !~ regex
source = file.split('/')
source.push(source.pop.gsub(regex, '.'))
non_digested = File.join(source)
if manifests.any? {|m|
if m.is_a? Regexp
m.match non_digested
else
m.ends_with?(non_digested)
end
}
puts "** copy source: #{file}"
puts "** copy destination: #{non_digested}"
FileUtils.cp(file, non_digested)
end
end
end
end
Rake::Task['assets:precompile'].enhance do
puts "Invoke nonfingerprint_assets"
Rake::Task['app:nonfingerprint_assets'].invoke
end
This rake task is working fine on my local machine even in production environment. It creates a file in public/assets/application.js which is the copy of the same file with a digest in its name.
When I deploy this code to heroku I get the following error message which I don't understand:
-----> Preparing app for Rails asset pipeline
Running: rake assets:precompile
[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_
locales = false to avoid this message.
Invoke nonfingerprint_assets
** copy source: /tmp/build_48b86bff-83f9-4d21-8b21-712c1baef811/public/assets/application-51d1660b66655782ab137ee98c789fdd.js
** copy destination: /tmp/build_48b86bff-83f9-4d21-8b21-712c1baef811/public/assets/application.js
rake aborted!
No such file or directory - /tmp/build_48b86bff-83f9-4d21-8b21-712c1baef811/public/assets/application.js
/tmp/build_48b86bff-83f9-4d21-8b21-712c1baef811/lib/tasks/production.rake:26:in `block (3 levels) in <top (required)>'
/tmp/build_48b86bff-83f9-4d21-8b21-712c1baef811/lib/tasks/production.rake:9:in `each'
/tmp/build_48b86bff-83f9-4d21-8b21-712c1baef811/lib/tasks/production.rake:9:in `block (2 levels) in <top (required)>'
/tmp/build_48b86bff-83f9-4d21-8b21-712c1baef811/lib/tasks/production.rake:45:in `block in <top (required)>'
Tasks: TOP => app:nonfingerprint_assets
(See full trace by running task with --trace)
Please help me to understand what's going on.
I'm struggling with this error after I fire the command rake apn:notifications:deliver on the APN on Rails gem that I've installed.
It's barking about the RAILS_ENV variable. I've tried a couple of forks that change RAILS_ENV to Rails.env but I still get the same error. I've posted my issue over on that repo hoping I might get somewhere.
I don't know enough about rails to dig in any further. I'm hoping someone could point me in the right direction so that I can a) better understand what went wrong and b) fix the problem.
I am using bundler and I'm pointing my gem file to the git repo: rake apn:notifications:deliver
air:apnapp azcoov$ rake apn:notifications:deliver --trace
/Users/azcoov/.bundler/ruby/1.8/apn_on_rails-ca98c7c130f0/lib/apn_on_rails/version.rb:2: warning: already initialized constant VERSION
** Invoke apn:notifications:deliver (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute apn:notifications:deliver
rake aborted!
uninitialized constant APN::App::RAILS_ENV
/Users/azcoov/.bundler/ruby/1.8/apn_on_rails-ca98c7c130f0/lib/apn_on_rails/app/models/apn/app.rb:11:in `cert'
/Users/azcoov/.bundler/ruby/1.8/apn_on_rails-ca98c7c130f0/lib/apn_on_rails/app/models/apn/app.rb:22:in `send_notifications'
/Users/azcoov/.bundler/ruby/1.8/apn_on_rails-ca98c7c130f0/lib/apn_on_rails/app/models/apn/app.rb:32:in `send_notifications'
/Users/azcoov/.bundler/ruby/1.8/apn_on_rails-ca98c7c130f0/lib/apn_on_rails/app/models/apn/app.rb:31:in `each'
/Users/azcoov/.bundler/ruby/1.8/apn_on_rails-ca98c7c130f0/lib/apn_on_rails/app/models/apn/app.rb:31:in `send_notifications'
/Users/azcoov/.bundler/ruby/1.8/apn_on_rails-ca98c7c130f0/lib/apn_on_rails/rails/../tasks/apn.rake:7
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `execute'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `invoke_with_call_chain'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `run'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/bin/rake:33
/usr/bin/rake:19:in `load'
/usr/bin/rake:19
Tasks: TOP => apn:notifications:deliver
Which version of Rails to you use? I just ran into this issue too. My Rails knowledge is not very deep, but it seems like the problem is deprecation of RAILS_* environment variables. I use Rails 3.1.0 and I do NOT have:
RAILS_ROOT/ENV/blah
in my environment. Instead, I have:
Rails.root/env/blah
When I replace RAILS_ENV with Rails.env in app/models/apn/app.rb the problem goes away.
So, is this gem compatible with Rails 3.1.0??? It seems not. Is there a workaround that will allow its use in a Production environment? Maybe define somewhere:
APN::App::RAILS_ENV = Rails.env
But where?
UPDATE:
I got it working with a workaround described by garyfoster here: https://github.com/PRX/apn_on_rails/issues/53.
To summarize, three things:
1) Add this ghetto hack to your config/environment.rb file:
APN::App::RAILS_ENV = Rails.env
2) Insert your certs in the APN::App table. I wrote a one-time rake task for that:
task :init_apn_certs => [:environment] do # NOTE: One-time task...
print "Creating APN::App with certs..."
app = APN::App.create(:apn_dev_cert => Rails.root.join('config', 'apple_push_notification_development.pem').read,
:apn_prod_cert => Rails.root.join('config', 'apple_push_notification_production.pem').read)
puts (app.valid? ? "done" : "failed")
end
3) Write your own rake task that bypasses the APN::App.send_notifications method, as that barfs with another error (something about '/config/apple_push_notification_development.pem' not existing). My code for it:
task :deliver_notifications => [:environment] do
print "Delivering APNs for app ids..."
apps = APN::App.all
apps.each do |app|
app.send_notifications
print app.id.to_s + "..."
end
puts "done."
end
Or, if you have only one app, you can just do this and be done with it:
task :deliver_notifications => [:environment] do
APN::App.first.send_notifications
end
DISCLAIMER: I'm yet to test this on Staging and Production (will do so by the end of the week), but I see no reason why it shouldn't work.