rake jobs:work Each time I start my server? - ruby-on-rails-3

I am using delayed jobs, because I have some long running processes running in the background.
The annoying part is that I need to run 'rake jobs:work' before I start my application everytime.
Is there any way to let my Rails application know that I want it to start every time I restart my server? or refresh my homepage?

Is this on your local machine? If so, you could just set an alias that you could run that would run 'rake jobs:work' when you use the alias. For example:
alias startserver='rake jobs:work & rails s'

Related

Start program via ssh in Jenkins and using it in Jenkins build

Hello people.
I'm using Jenkins as CI server and I need to run some performance test using Jmeter. I've setup the plugin and configured my workspace and everything works ok, but I have to do some steps manually and I want a bit more of "automation".
Currently i have some small programs in a remote server. These programs make some specific validations, for instance (just to explain): validates e-mail addresses, phone numbers, etc.
So, before I run the build in jenkins, I have to manually start the program (file.sh) I want:
I have to use putty (or any othe ssh client) to conect to the server and then run, for instance, the command
./email_validation.sh
And the Jmeter test runs in a correct way, and when the test is done I have to manually "shut down" the program I started. But what I want is trying to start the program I need in Jenkins configuration (not manually outside Jenkins, but in "execute shell" or "execute remote shell using ssh" build step).
I have tried to start it, but it get stuck, because when Jenkins build finds the command
./email_validation.sh
the build stops, it waits for the command to finish and then it will continue the other build steps, but obviously, I need this step not to finish until the test is executed.
Is there a way to achieve this? Thanks
Run your command as a background process by adding the & symbol at the end of the command and use the nohup command in case the parent process gets a hangup signal, e.g.
nohup /path/to/email_validation.sh &
If the script produces any output, it will go by default to the file nohup.out in the current directory when the script was launched.
You can kill the process at the end of the build by running:
pkill email_validation.sh

Rails run rake:scheduler after start server

I need to run a rake command after starting a rails server.
However, when I try to call system(rake reque:scheduler") in config.before_initialise,
the command appears to run in an infinate loop.
I've searched other sites for an answer, but I'm not finding it.
You don't want to start that process inside Rails. Take a look at Foreman: https://github.com/ddollar/foreman

does Delayed_job daemon not run in development?

I'm using delayed_job and I am able to run jobs using rake jobs:work but using the daemonized version, it does nothing although I see it in the process list.
I'm using:
rails (3.0.9)
delayed_job (2.1.4)
daemons (1.0.10)
I'm running delayed_job using:
unix>RAILS_ENV=development script/delayed_job start
It could be a problem loading a custom job class file. To test that, try this:
Enter the rails console rails console --sandbox.
Make sure you have a job in the table job = Delayed::Job.first.
Try YAML.load(job.handler). If you get an error that looks like this: ArgumentError: undefined class/module MyCustomClass, it's probably a problem loading your custom job
Still in the rails console, run require 'My_Custom_Class. Then run the YAML.load(job.handler) command again. If this returns the appropriate object it's definitely a class loading problem.
To fix the problem create the file config/initializers/custom.rb and in it put require 'My_Custom_Class'.
You should then be able to run rake jobs::workoff and get something that looks like this:
[Worker(host:my.host pid:5085)] Starting job worker
[Worker(host:my.host pid:5085)] MyCustomJob completed after 0.0774
[Worker(host:my.host pid:5085)] 1 jobs processed at 9.1935 j/s, 0 failed ...
[Worker(host:my.host pid:5085)] No more jobs available. Exiting
To answer your question we may need more information.
Are jobs added to database? Are there any errors in jobs?
What's the result of RAILS_ENV=development script/delayed_job status as I already mentioned?
Second, did you went through the most common problems Wiki page?
https://github.com/collectiveidea/delayed_job/wiki/Common-problems

Delayed Job failing in Production environment on Server

I am using delayed_job gem for sending emails in my rails app.
delayed_job was working well but from last 5 days, it is not working and throwing following error in delayed_job.log file.
2011-10-09T01:53:04+0530: [Worker(delayed_job host:backupserver pid:23953)] Syck::DomainType#private_group_join_request failed with NoMethodError: undefined method private_group_join_request' for # - 11 failed attempts
2011-10-09T01:53:04+0530: [Worker(delayed_job host:backupserver pid:23953)] 1 jobs processed at 1.4503 j/s, 1 failed ...
2011-10-09T01:54:40+0530: [Worker(delayed_job host:backupserver pid:23953)] Syck::DomainType#contact_us_email failed with NoMethodError: undefined method contact_us_email for # - 11 failed attempts
2011-10-09T01:54:40+0530: [Worker(delayed_job host:backupserver pid:23953)] 1 jobs processed at 4.3384 j/s, 1 failed ...
Following is one of the example how I am calling delayed job for sending email.
UserMailer.delay(:run_at => 10.seconds.from_now).contact_us_email(self)
I am starting delayed job with
RAILS_ENV=production script/delayed_job start
It is working correctly in development as well as production environment on my local machine.
Environment Which I am using in Rails App.
Rails 3.0.8
Ruby 1.9.2 in Linux(Ubuntu)
rake 0.9.2
delayed_job 2.1.4
This is same as
Undefined Method Error when creating delayed_job workers with script/delay_job
But solution is not working for me.
I figured it out. It was due to package "libyaml" package, which was not present on my local system but was installed on server.
Is it possible that you didn't stop and start your delayed_job worker when you deployed some new code? If a worker that was running before the deploy is trying to run new methods, it will fail.
Is it possible that YAML (or Syck) running in the worker process doesn't know about the method in question? Take a look at:
https://github.com/collectiveidea/delayed_job/wiki/Common-problems#wiki-jobs_are_silently_removed_from_the_database
... the relevant part is:
One common cause of deserialization errors is that the YAML references
a class not known to the worker. If this is the case, you can add
# file: config/initializers/custom.rb
require 'my_custom_class'
which will force my_custom_class to be loaded when the worker starts.
I had to restart my unicorns on the production server, by hand because for some reason cap deploy was not doing it for me.
So what I had to do was:
sudo /etc/init.d/unicorn_myapp stop
sudo /etc/init.d/unicorn_myapp start
But unicorn wasn't able to start, so I had to
sudo rm /tmp/unicorn.my_app.sock
And
sudo /etc/init.d/unicorn_myapp start

Monitoring of a Rake Task and Controling it

I would like to get the status of a Rake Task into my backoffice(That means Running or not running).
And I also would like to start the rake task if it is not running. Otherwise I want to quit it.
Any idea?
You can look at this part of a gist: https://gist.github.com/1003601#file_delayed_delta.sh
Basically, I save the PID of the rake task to PIDFILE, then use monit to see if it is running.
https://gist.github.com/1003601#file_monitrc
You could also have a cronjob that runs a system command like ps -ef | grep my_rake_task and see if anything turns up. This may or may not require less effort.