Cron Job issu with rails - gem whenever - ruby-on-rails-4

I am trying to do a simple Cron task using the gem whenever for rails.
How can I tell whenever to trigger a controller action ?
What I wan to do :
every 1.minute do
runner "Mycontroller.index", :environment => 'development'
end
What i want to do is to trigger the action index in my DataController every minute. The index action trigger a mailer.
I run : whenever --update-crontab football
also when I start/restart my server I get a tinny message as follow:
You have new mail in /var/mail/Antoine
[2015-04-12 18:38:17] INFO WEBrick 1.3.1 [2015-04-12 18:38:17] INFO
ruby 2.1.3 (2014-09-19) [x86_64-darwin14.0] [2015-04-12 18:38:17] INFO
WEBrick::HTTPServer#start: pid=22476 port=3000 ^C[2015-04-12 18:38:52]
INFO going to shutdown ... [2015-04-12 18:38:52] INFO
WEBrick::HTTPServer#start done. Exiting
You have new mail in
/var/mail/Antoine

Okay I figured it out:
every 1.day, :at => '4:30 am' do
command "curl http://localhost:3000", :environment => 'development'
end
I use the command curl to got to the route where I wish to trigger a controller action.
I also understood that I need to run whenever -w to write the cron task and then I can do crontab -l to see my ongoing cron tasks and if I wan to remove cron taks I just need to run crontab -r

Related

Sidekiq Upstart on AmazonLinux 2018.03

My goal is to add the sidekiq service to upstart on AmazonLinux 2018.03.
Since I want to upgrade sidekiq to version 6, There are needs to manage the process by OS like upstart.
I put a file to /etc/init/sidekiq.conf from here.
After that, initctl list | grep sidekiq command shows nothing, so I tried sudo initctl reload-configuration, but nothing changed.
status sidekiq command shows status: Unknown job: sidekiq.
What else do I need to do to add the sidekiq service to upstart?

How to Trigger a Workflow B start right after Workflow A completed?

I am new to Informatica Power Center.
My task is to trigger/start Workflow B right after when Workflow A just completed using infacmd command.
Suggestion is after all session in workflow a add a command task with "infacmd.sh startworkflow" to start the workflow b with all the options.
I've tried some guides but the version was too old. I'm using Informatica 10.1.1.
Thank you.
Fro the command task you can use the following command.
pmcmd startworkflow -sv $INFA_SERVICE -d $INFA_DOMAIN -u $INFRAREPO_USERID -p $INFRAREPO_PASSWD -f $INFA_FOLDER -wait $INFA_WORKFLOW
Replace the variable according to your domain/folder/workflow name etc.
Otherwise, you can create a shell script from where you have to call the workflow using the above command and call the shell script from your last session 'Post Session success command'
Consider creating a Command task that will touch a file and having Workflow B started together with Workflow A, with a Wait task that will wait for a file, and delete the file as a last step.
This way you don't need to invoke the pmcmd with hardcoded username and password.

chef - restart a service on another machine after connecting to it

I'm new to chef and struggling with this concept - I'm not sure if it's possible and if it is, how to achieve it. Thus far Google Fu has failed me.
I have a chef client and chef server, i'm uploading cookbooks to run on my client. I trigger the code by running chef-client on the chef client machine.
What I'm then trying to do is connect to several other boxes via ssh and then stop a service, clear out a directory and restart the service.
When working I'll be targeting Solr service
My basic test code is as follows:
ruby_block 'do something' do
block do
Chef::Log.info('Do Something')
Chef::Resource::Notification.new('stop', :run, self)
end
end
#define the service - does nothing
service 'atd' do
action :nothing
end
#do something that triggers
execute 'start' do
command 'pwd'
Chef::Log.info('triggers start')
action :nothing
notifies :start, run_context.resource_collection.find(:service => 'atd')
end
execute 'stop' do
# some stuff
# on success...
command 'pwd'
Chef::Log.info('triggers restart')
notifies :stop, run_context.resource_collection.find(:service => 'atd'), :immediately
notifies :run, 'execute[start]'
end
in the ruby block I plan on iterating through a list of machines that I have and ssh'ing to them. Is it then possible to run the remainder of the code on those machines?
Thanks for any help / advice.

Gem 'whenever' in rails 4

I try to send message automatically by using whenever gem. I am in initial step. I install the gem 'whenever'. I done the following step.
1. Add "gem 'whenever', :require => false" to the gemfile.
2. bundle install.
3. wheneverize .
4. in schedule.rb add the following code,
set :output, "#{path}/log/cron.log"
#every 1.day, :at => '4:30 am' do
every 5.minutes do
runner "Payment.sendMessage", :environment => "development"
end
5.And model likes,
class Payment < ActiveRecord::Base
def sendMessage
puts"Hello"
end
end
6. When I use bundle exec whenever, I get like the following issue as
0,5,10,15,20,25,30,35,40,45,50,55 * * * * /bin/bash -l -c
'cd /home/prabha/rails_job && bundle exec bin/
rails runner -e development '\''Payment.sendMessage'\'' >>
/home/prabha/rails_job/log/cron.log 2>&1'
## [message] Above is your schedule file converted to cron syntax;
your crontab file was not updated.
## [message] Run `whenever --help' for more options.
I am stuck with this step. what I want to do the further proceed? Anyone guide me.
Thanks.
You need to update you crontab file.
Do the following -
whenever --update-crontab
For more information, please check whenever gem's Github ReadMe page.
1) sendMessage should be a class method.
2) You can use "whenever" command in your project directory to see the cron configuration and then copy into your crontab.

AWS CodePipeline advanced tutorial with jenkins

I'm running through AWS CodePipeline tutorial and there is this step
saying that I have to create a jenkins job running bash script which will connect to the EC2 instance (not the one where jenkins is running, but the one where the code has been deployed earlier).
It is said that I have to connect to the EC2 instance by running this command in bash script:
TEST_IP_ADDRESS=192.168.0.4 rake test
But my gut feeling is saying that this step is completely wrong.
There is no variable with this name, and there is no option to connect to external instance just like that.
I've completed all the steps successfully, but this one is obviously wrong
The bash script will run in your jenkins instance, and it will make an HTTP request to the instance you configured in TEST_IP_ADDRESS.
When you add the "build step", and choose "Execute shell", you'll enter this:
TEST_IP_ADDRESS=192.168.0.4 rake test
You are defining the TEST_IP_ADDRESS variable, so it's up to you to give it an appropriate value.
First I had the same confusion, then I saw the source code and it is pretty self-explained:
#!/usr/bin/env ruby
require 'net/http'
require 'minitest/autorun'
require 'socket'
class JenkinsSampleTest < MiniTest::Unit::TestCase
def setup
uri_params = {
:host => ENV['TEST_IP_ADDRESS'] || 'localhost',
:port => (ENV['TEST_PORT'] || '80').to_i,
:path => '/index.html'
}
#webpage = Net::HTTP.get(URI::HTTP.build(uri_params))
end
def test_congratulations
assert(#webpage =~ /Congratulations/)
end
end