Delayed Job in Rails 4 with Capistrano - ruby-on-rails

I cant figure how to start Delayed Jobs on a dedicated Ubuntu server.
It works fine on my localhost but when I run on my server
sudo RAILS_ENV=production bin/delayed_job restart
I get
sudo: bin/delayed_job: command not found
On top of that, if I run the "rake jobs:work RAILS_ENV=production" command Im getting the following error:
PG::FeatureNotSupported: ERROR: SELECT FOR UPDATE/SHARE is not allowed in subqueries
Apparently theres an issue with my psql version.
Is there any way I can get the script to work? Any effective Capistrano recipes available? All ive found on the web are old recipes for Rails 3 and older versions of capistrano.
Thanks in advance.
EDIT:
I have already bundled install the daemons gem and generated "delayed_job:active_record" on my local machine, then proceded to cap deploy which bundle installed and migrated in the production server.
The bin/delayed_job file exists in the server yet it fails with command not found.

And add this to config/environment.rb:
ENV['RAILS_ENV'] ||= 'production'
Then at your production server:
RAILS_ENV=production rake db:migrate
RAILS_ENV=test production generate delayed_job:active_record && RAILS_ENV=production rake db:migrate
Now after you do that:
RAILS_ENV=production script/delayed_job start
As for Capistrano error you are facing, please try to add the command like:
run "cd #{current_path}; #{sudo} RACK_ENV=production bundle exec #{current_path}/bin/delayed_job start"

You must run this on target server:
bundle exec rails generate delayed_job

Related

Existing Redmine Project from Linux to Windows: Redmine is not migrated

This is the error I encounter during rake.
The Easy Project cannot start because the Redmine is not migrated!
Please run bundle exec rake db:migrate RAILS_ENV=production and than
bundle exec rake easyproject:install RAILS_ENV=production rake
aborted!
I try to run the command stated and it doesn't work.
Do I need to install something? Because the bundle install is successful.
I thought running the bundle install after giving me the project will do.
The first developer used Linux, but im on Windows.
Already resolved. I used these ffg commands:
bundle exec rake generate_secret_token
set RAILS_ENV=production
bundle exec rake db:migrate

rails assest:precomplie , when load file not correct

I have web RoR, I ran assets:precomplie, and i got file
**/application-dfaaca6b25e0d101d80f81c5cb194f6d39d331886613c0a392283b01b9911cb0.css**
but my web was loaded another file
**application.self-a429e1a197d1ad3e5a775f50a60fd344db3ba490db151ab8c7494a78cba792a2.css**.
i don't know reason. Anybody, can help me? Thanks a lot
I got the same questions. then finally I find the answer:
when you process assets:precomplie, you must specify the env as you run rails, because in different enviroments, the assets version is not same!
when you run rails in development env as rails s, you should process as rake assets:precomplie or assets:precomplie RAILS_ENV=development
when you run rails in production env as rails s -e p, you should process as rake assets:precomplie RAILS_ENV=production
hope this helps!
Solution:
Deploy your application again
if still not solved
SSH into the system
delete the file your_app/manifest_backup
$ bundle exec rake assets:clear
$ bundle exec rake assets:precompile RAILS_ENV=production
restart the webserver ( for Nginx /etc/init.d/nginx restart or $ sudo service nginx restart )
if still not solved deploy your app again
For more info see my blog
https://cbabhusal.wordpress.com/2015/07/20/ruby-on-rails-production-staging-when-asset-path-is-outdated/

Running RAILS_ENV=production with the system command

I have got a really weird problem with a script that I am running on my server, the details are below. But essentially I am using a script to set up a rails application and I am calling that script from an existing rails application.
In my existing application (the application that is calling the script on the server) I have:-
Spawnling.new do
system "cd ~/ && ~/*/create_site.sh param1 param2 >> /tmp/logger"
end
The create_site.sh script creates a fresh installation of rails using the below:
rails new $DIR --database postgresql
It then does a number of things to set up the application. The issue is that the script seems to run absolutely fine until it gets to the following command:
cd $DIR && RAILS_ENV=production rails g roroacms:install -v && RAILS_ENV=production rake assets:clean && RAILS_ENV=production rake assets:precompile
It is really odd because when I run the top command manually as the root user it seems to run absolutely fine without any issues at all. When I view the logger file at the end of the top command it looks like the below:
Your bundle is updated!
Bundle is installed and up to date
RoroaCMS installation
Installation complete with assets
Server started
When I run this manually it outputs a number of messages between each line where it is running the command. Any ideas on this? I am thinking that it could be something to do with RAILS_ENV as the rails new command runs fine earlier in the script.
Hi I do a fair bit of scripting rails on servers and I always use the format bundle exec rails g rspec:install production so your command would be cd $DIR && bundle exec rails g roroacms:install -v production && bundle exec rake assets:clean production && bundle exec rake assets:precompile production. I dont have a whole lot of reasoning behind it but that format seems to be most reliable across different server environments.

Capistrano deploy:migrate Could not find rake-0.9.2.2 in any of the sources

My Capistrano deploy:migrate task is set to run a simple rake db:migrate command, as follows:
env PATH=/home/user/.gems/bin sh -c 'cd /home/user/app/releases/20121003140503 && rake RAILS_ENV=production db:migrate'
When I run this task during an ssh session manually it completes successfully. However when I run from my local development box, I receive the following error:
** [out :: app] Could not find rake-0.9.2.2 in any of the sources
I am able to locate my rake gem by typing which rake via ssh (/home/user/.gems/bin/rake) and rake --version gives me "rake, version 0.9.2.2," so I don't understand why this command fails via Capistrano?
Capistrano does not place bundle exec before rake command in default. If you are sure you have the rake gem in your bundle, try adding this to your deploy.rb.
set :rake, 'bundle exec rake'
This will tell Capistrano to instead of just rake run bundle exec rake. If it is in your bundle, you won't have any problems any more and you will also avoid collisions if you have more versions of rake installed on your system.
You might also just need to bundle your gems with this:
require "bundler/capistrano"
Via: Why is Capistrano not installing gems with bundler?
Once you go into your app folder, you simply type:
$bundle exec rake instead of just $rake

How to start delayed job workers in production mode

I was following railscast for delayed job. Things are working perfectly on my machine. How can start delayed_job workers in production mode?
I am using delayed_job gem,(2.1.4)
RAILS_ENV=production script/delayed_job start
For Rails 4
RAILS_ENV=production bin/delayed_job start
Solved my problem.
It may give you an error that tmp directory doesn't exists. Just create one and run previous command again..
You can try to run the following command:
RAILS_ENV=production cd ~/path_to_your_app/current && /usr/local/bin/ruby ./script/delayed_job start
where you should adjust /usr/local/bin/ruby based on your production server ruby configuration.

Resources