Re: Problem with crontab and script/runner

Jose vicente Ribera pellicer
Thu, 23 Apr 2009 08:51:47 -0000

Wang Pengcheng wrote:
> Sometimes you should test the file which is executed or not.
> So I suggest you can write some code in the script to show whether it
> work or not, such as
> `date >> ~/test.txt`
> After testing it ,you can permit the situation.
>
> On Apr 21, 5:12�pm, Jose vicente Ribera pellicer <rails-mailing-

I try with this:

*       *       *       *       *       echo
"hola">>/Users/jose/prueba.txt

and it works perfectly.
-----------------------------
-----------------------------

This is my code...

crontab:

*       */6       *       *       *       /opt/local/bin/ruby
/Users/jose/mimandote.com/script/runner ''Usuario.new_usr_dia''

In my aplication

In usuario.rb -->Selects the new user of the day

 def self.new_usr_dia
    cambiado = false
    Usuario.all(:conditions => "usuario_del_dia is NULL", :order
=>
"posicion_ranking", :limit => 200).each do |usuario|
      if cambiado == false and usuario.avatar.existe? # El usuario del
dia tiene que tener avatar

usuario.update_attribute(''usuario_del_dia'',Time.now.to_s(:db))
        cambiado = true
      end
    end
    ''UPDATE usuarios SET usuario_del_dia = NULL''.lanza_sql
if
cambiado == false
  end

--------------------------------
In avatar.rb:

The constant DIRECTORIO:

DIRECTORIO = File.join("public", "images",
"avatar")
(I change it to this -->DIRECTORIO File.join(Rails.public_path,
"images", "avatar"). This error doesn´t
appears now:

/opt/local/lib/ruby/gems/1.8/gems/rails-2.1.2/lib/commands/runner.rb:47:
/Users/jose/mimandote.com/app/models/avatar.rb:21:in `mkdir'': No such
file or directory - public/images/avatar (Errno::ENOENT)

But the day usuary doesn''t change :(

Some methods:

 def initialize(usuario, imagen=nil)   #It creates the directory if
doesn`t exists
    @usuario = usuario
    @imagen = imagen
    Dir.mkdir(DIRECTORIO) unless File.directory?(DIRECTORIO)
  end

  def existe?
    logger.debug "AVATAR.RB(existe?): directorio #{DIRECTORIO} - todo
#{File.join(DIRECTORIO, nombre_archivo)}"
    File.exists?(File.join(DIRECTORIO, nombre_archivo))
  end

------
Read
------
It''s very strange for me that before I tried to run in background this
method it runs perfecly running it from application''s control zone. I
only do this from my controller

def accion_control
....
 Usuario.new_usr_dia if params[:accion] == ''new-usr-dia''
...
end


PD.
Sorry...because i know my enlish is not the best.
Thanks a lot!!