List Info

Thread: Cron and rails




Cron and rails
country flaguser name
Germany
2007-06-09 07:13:11
Hi, i've a little problem. i've to run a method every 5
minutes with
cron, but i don't know what and where i've to write it. The
method is
written, but to run it ? i know that i've to use the
script/runner (does
it take a lot of resources? does exist something better?),
but to run it
every 5 minutes?
* 5 * * * script/runner -e production
"Class.method" ?
and in which file should i put it ? (i'm under gentoo with
vixie-cron)
Thanks

-- 
Posted via http://www.ruby-forum.com
/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Deploying Rails" group.
To post to this group, send email to
rubyonrails-deploymentgooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-deployment-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-deployment
?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Cron and rails
country flaguser name
United States
2007-06-09 07:34:06

On Jun 9, 2007, at 5:13 AM, mike wrote:

>
> Hi, i've a little problem. i've to run a method every 5
minutes with
> cron, but i don't know what and where i've to write it.
The method is
> written, but to run it ? i know that i've to use the
script/runner  
> (does
> it take a lot of resources? does exist something
better?), but to  
> run it
> every 5 minutes?
> * 5 * * * script/runner -e production
"Class.method" ?
> and in which file should i put it ? (i'm under gentoo
with vixie-cron)
> Thanks
>
>

I'd create a shell script on your server(s) to do this.

edit ~/scheduled-tasks/my-scheduled-task-name
##########
#!/bin/sh
# change directory
export RAILS_ENV=production
cd ~/path/to/rails/app
ruby scipt/runner "Class.method"
#########

chmod +x ~/scheduled-tasks/my-scheduled-task-name

crontab entry:

* 5 * * * $HOME/scheduled-tasks/my-scheduled-task-name

Something along those lines should work.


Robby

--
Robby Russell
Founder and Executive Director

PLANET ARGON, LLC
Ruby on Rails Development, Consulting & Hosting

www.planetargon.com
www.robbyonrails.com

+1 503 445 2457
+1 877 55 ARGON [toll free]
+1 815 642 4068 [fax]



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Deploying Rails" group.
To post to this group, send email to
rubyonrails-deploymentgooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-deployment-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-deployment
?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Cron and rails
user name
2007-06-09 07:35:58
Hi,

Add following to a file(for e.g. cron_tasks.txt)

daily RAILS_ENV=production /path/to/app/script/runner Controller(or Model or Mailer).method

Add above file to crontab(cron table) by issuing following command,
crontab cron_tasks.txt

For specifics of crontab, look at following,
http://www.adminschoice.com/docs/crontab.htm#Crontab%20file


-Jatinder


On 6/9/07, mike < ruby-forum-incomingandreas-s.net">ruby-forum-incomingandreas-s.net> wrote:

Hi, i've a little problem. i've to run a method every 5 minutes with
cron, but i don't know what and where i've to write it. The method is
written, but to run it ? i know that i've to use the script/runner (does
it take a lot of resources? does exist something better?), but to run it
every 5 minutes?
* 5 * * * script/runner -e production "Class.method&quot; ?
and in which file should i put it ? (i'm under gentoo with vixie-cron)
Thanks

--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Deploying Rails"; group.
To post to this group, send email to rubyonrails-deploymentgooglegroups.com
To unsubscribe from this group, send email to rubyonrails-deployment-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-deployment?hl=en
-~----------~----~----~----~------~----~------~--~---

Re: Cron and rails
country flaguser name
Germany
2007-06-09 07:57:26
Robby Russell wrote:
> I'd create a shell script on your server(s) to do
this.
>
> crontab entry:
> 
> * 5 * * * $HOME/scheduled-tasks/my-scheduled-task-name
> 


Why create an external script?
This http://www.adminschoice.com/docs/crontab.htm#Crontab%
20file says 
that the second is for hours:

> A line in crontab file like below  removes the tmp
files from /home/someuser/tmp each day at 6:30 PM.
>
> 30     18     *     *     *         rm
/home/someuser/tmp/* 

But with something like

5 * * * * .....

it would be run every hour at 5 minutes, like 01:05, 02:05,
and so on, 
right ?

with:

* * * * * ....

it would be run every minutes...but every 5 minutes? :(


-- 
Posted via http://www.ruby-forum.com
/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Deploying Rails" group.
To post to this group, send email to
rubyonrails-deploymentgooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-deployment-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-deployment
?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Cron and rails
country flaguser name
United States
2007-06-09 08:24:24

On Jun 9, 2007, at 5:57 AM, mike wrote:

>
> Robby Russell wrote:
>> I'd create a shell script on your server(s) to do
this.
>>
>> crontab entry:
>>
>> * 5 * * *
$HOME/scheduled-tasks/my-scheduled-task-name
>>
>
>
> Why create an external script?

I prefer an external script so that I can add some
documentation if  
necessary for whomever else might come across this crontab.
Also, it  
allows me to test the script and run it manually when
necessary.

We often have special rake tasks and shell scripts that go
along with  
our rails applications, and we maintain them in subversion,
so, this  
allows us to modify them within svn without needing to
re-edit our  
crontab each time there is a change.

> This http://www.adminschoice.com/docs/crontab.htm#Crontab%
20file says
> that the second is for hours:

Every five minutes:

0,5,10,15,20,25,30,35,40,45,50,55, * * * * path/to/script

good luck!

Robby
--
Robby Russell
Founder and Executive Director

PLANET ARGON, LLC
Ruby on Rails Development, Consulting & Hosting

www.planetargon.com
www.robbyonrails.com

+1 503 445 2457
+1 877 55 ARGON [toll free]
+1 815 642 4068 [fax]



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Deploying Rails" group.
To post to this group, send email to
rubyonrails-deploymentgooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-deployment-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-deployment
?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Cron and rails
country flaguser name
Germany
2007-06-09 08:30:17
Robby Russell wrote:

> I prefer an external script so that I can add some
documentation if
> necessary for whomever else might come across this
crontab. Also, it
> allows me to test the script and run it manually when
necessary.
> 
> We often have special rake tasks and shell scripts that
go along with
> our rails applications, and we maintain them in
subversion, so, this
> allows us to modify them within svn without needing to
re-edit our
> crontab each time there is a change.
> 

> 
> Every five minutes:
> 
> 0,5,10,15,20,25,30,35,40,45,50,55, * * * *
path/to/script
> 
> good luck!
> 

ok, i think i'll use an external script too 
what about the resources? does it takes a lot (of memory) to
start ?

-- 
Posted via http://www.ruby-forum.com
/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Deploying Rails" group.
To post to this group, send email to
rubyonrails-deploymentgooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-deployment-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-deployment
?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Cron and rails
country flaguser name
United States
2007-06-09 09:05:05

On Jun 9, 2007, at 6:30 AM, mike wrote:

>
> Robby Russell wrote:
>
>> I prefer an external script so that I can add some
documentation if
>> necessary for whomever else might come across this
crontab. Also, it
>> allows me to test the script and run it manually
when necessary.
>>
>> We often have special rake tasks and shell scripts
that go along with
>> our rails applications, and we maintain them in
subversion, so, this
>> allows us to modify them within svn without needing
to re-edit our
>> crontab each time there is a change.
>>
>
>>
>> Every five minutes:
>>
>> 0,5,10,15,20,25,30,35,40,45,50,55, * * * *
path/to/script
>>
>> good luck!
>>
>
> ok, i think i'll use an external script too 
> what about the resources? does it takes a lot (of
memory) to start ?

It really depends on what your method is doing... You might
try  
running it manually and watch your processes in top.

-Robby

--
Robby Russell
Founder and Executive Director

PLANET ARGON, LLC
Ruby on Rails Development, Consulting & Hosting

www.planetargon.com
www.robbyonrails.com

+1 503 445 2457
+1 877 55 ARGON [toll free]
+1 815 642 4068 [fax]



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Deploying Rails" group.
To post to this group, send email to
rubyonrails-deploymentgooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-deployment-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-deployment
?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Cron and rails
country flaguser name
Germany
2007-06-09 09:19:48
Robby Russell wrote:
>
> It really depends on what your method is doing... You
might try
> running it manually and watch your processes in top.
>

I'll try
Thanks 

-- 
Posted via http://www.ruby-forum.com
/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Deploying Rails" group.
To post to this group, send email to
rubyonrails-deploymentgooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-deployment-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-deployment
?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Cron and rails
user name
2007-06-09 10:41:10
Most cron implementations also support this format
*/5 * * * * /path/to/script

Beware that the full rails stack has gotten quite large and
loading
and unloading it from cron can be painful. If you don't need
all of
rails (for ex. ActionPack), just load what you need. Here's
a quick
script that loads active record and all the models in a
rails project.
It hasn't been tested, but should get you most of the way
there.

#!/usr/bin/env ruby

require 'rubygems'
require 'active_record'
require 'action_mailer'

connection =
YAML::load(open('../config/database.yml'))["development
"]
connection["database"] = "../" +
connection["database"] if
connection["adapter"].match(/sqlite/)

ActiveRecord::Base.establish_connection(connection)

Dir["../app/models/*"].each {|m| require m}

puts Link.find(:all).inspect

On 6/9/07, mike <ruby-forum-incomingandreas-s.net> wrote:
>
> Robby Russell wrote:
> >
> > It really depends on what your method is doing...
You might try
> > running it manually and watch your processes in
top.
> >
>
> I'll try
> Thanks 
>
> --
> Posted via http://www.ruby-forum.com
/.
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Deploying Rails" group.
To post to this group, send email to
rubyonrails-deploymentgooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-deployment-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-deployment
?hl=en
-~----------~----~----~----~------~----~------~--~---


[1-9]

about | contact  Other archives ( Real Estate discussion Medical topics )