I am using the daemons plugin.
I have just one problem how do i add modules from the /lib folder to
the /lib/daemons/daemon.rb file
eg. /lib/basic_functions.rb
this is the file i want to load in daemon.rb
contents daemon.rb:
#!/usr/bin/env ruby
# You might want to change this
ENV["RAILS_ENV"] ||= "production"
require File.dirname(__FILE__) + "/../../config/environment"
#require File.dirname(__FILE__) + "/../../lib/basic_functions.rb"(this
didn''t work)
#require ''../basic_functions.rb'' (this didn''t work)
$running = true
Signal.trap("TERM") do
$running = false
end
while($running) do
# Replace this with your code
get_current_time
ActiveRecord::Base.logger.info "This daemons is still running at #
{@current_time}.\n"
sleep 5
end
contents of basic_functions
module BasicFunctions
def get_current_time
#@current_time = Time.now.beginning_of_month + 27.days
#@current_time = Time.now.beginning_of_month + 13.days
@current_time = Time.now
end
def get_time_period
get_current_time
@absmid = @current_time.beginning_of_month + 14.days
@midperiod = @absmid - 2.days
if @current_time >= @absmid
@begin_bid_time = @absmid
@end_bid_time = @current_time.next_month.beginning_of_month -
2.days
@ad_window_begin = @current_time.next_month.beginning_of_month
@ad_window_end = @current_time.next_month.beginning_of_month +
15.days
else
@begin_bid_time = @current_time.beginning_of_month
@end_bid_time = @midperiod
@ad_window_begin = @absmid
@ad_window_end = @current_time.next_month.beginning_of_month
end
end
end
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2009-Apr-07 07:46 UTC
Re: /lib daemon folder: how do i add a module into the daemon?
On Apr 7, 7:52 am, tyliong <tyli...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I am using the daemons plugin. > > I have just one problem how do i add modules from the /lib folder to > the /lib/daemons/daemon.rb file > > eg. /lib/basic_functions.rb > > this is the file i want to load in daemon.rb > > contents daemon.rb: > > #!/usr/bin/env ruby > > # You might want to change this > ENV["RAILS_ENV"] ||= "production" > > require File.dirname(__FILE__) + "/../../config/environment" > #require File.dirname(__FILE__) + "/../../lib/basic_functions.rb"(this > didn''t work) > #require ''../basic_functions.rb'' (this didn''t work) >requiring that file just means that the module BasicFunctions is now loaded. you haven''t done anything with it yet (include BasicFunctions somewhere might be a good starting point) Fred --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2009-Apr-07 07:57 UTC
Re: /lib daemon folder: how do i add a module into the daemon?
On Apr 7, 9:03 am, "Tan YL" <tyli...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thanks Fred. > > I tried what u said but I wasn''t able to get it going. This time I didn''t > require the file I dumped the module inside the daemons.rb file but I just > couldn''t get it to work. I know it must be something to do with the syntax I > used.where the module is on disk is somewhat irrelevant.> include Basic_functionsThat must match the name of the module Fred --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Tan YL
2009-Apr-07 08:03 UTC
Re: /lib daemon folder: how do i add a module into the daemon?
Thanks Fred.
I tried what u said but I wasn''t able to get it going. This time I
didn''t
require the file I dumped the module inside the daemons.rb file but I just
couldn''t get it to work. I know it must be something to do with the
syntax I
used.
#!/usr/bin/env ruby
# You might want to change this
ENV["RAILS_ENV"] ||= "development"
#require ''basic_functions.rb''
require File.dirname(__FILE__) + "/../../config/environment"
module BasicFunctions
def get_current_time
#@current_time = Time.now.beginning_of_month + 27.days
#@current_time = Time.now.beginning_of_month + 13.days
@current_time = Time.now
end
def get_time_period
get_current_time
@absmid = @current_time.beginning_of_month + 14.days
@midperiod = @absmid - 2.days
if @current_time >= @absmid
@begin_bid_time = @absmid
@end_bid_time @current_time.next_month.beginning_of_month - 2.days
@ad_window_begin @current_time.next_month.beginning_of_month
@ad_window_end @current_time.next_month.beginning_of_month + 15.days
else
@begin_bid_time @current_time.beginning_of_month
@end_bid_time = @midperiod
@ad_window_begin = @absmid
@ad_window_end @current_time.next_month.beginning_of_month
end
end
end
include Basic_functions
$running = true
Signal.trap("TERM") do
$running = false
end
while($running) do
# Replace this with your code
get_current_time
ActiveRecord::Base.logger.info "This daemons is still running at
#{@current_time}.\n"
sleep 5
end
-----Original Message-----
From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
[mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of
Frederick Cheung
Sent: Tuesday, April 07, 2009 3:46 PM
To: Ruby on Rails: Talk
Subject: [Rails] Re: /lib daemon folder: how do i add a module into the
daemon?
On Apr 7, 7:52 am, tyliong
<tyli...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> I am using the daemons plugin.
>
> I have just one problem how do i add modules from the /lib folder to
> the /lib/daemons/daemon.rb file
>
> eg. /lib/basic_functions.rb
>
> this is the file i want to load in daemon.rb
>
> contents daemon.rb:
>
> #!/usr/bin/env ruby
>
> # You might want to change this
> ENV["RAILS_ENV"] ||= "production"
>
> require File.dirname(__FILE__) + "/../../config/environment"
> #require File.dirname(__FILE__) +
"/../../lib/basic_functions.rb"(this
> didn''t work)
> #require ''../basic_functions.rb'' (this didn''t
work)
>
requiring that file just means that the module BasicFunctions is now
loaded. you haven''t done anything with it yet (include BasicFunctions
somewhere might be a good starting point)
Fred
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Tan YL
2009-Apr-07 08:14 UTC
Re: /lib daemon folder: how do i add a module into the daemon?
Thank you fred very very much. -----Original Message----- From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of Frederick Cheung Sent: Tuesday, April 07, 2009 3:57 PM To: Ruby on Rails: Talk Subject: [Rails] Re: /lib daemon folder: how do i add a module into the daemon? On Apr 7, 9:03 am, "Tan YL" <tyli...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thanks Fred. > > I tried what u said but I wasn''t able to get it going. This time I didn''t > require the file I dumped the module inside the daemons.rb file but I just > couldn''t get it to work. I know it must be something to do with the syntaxI> used.where the module is on disk is somewhat irrelevant.> include Basic_functionsThat must match the name of the module Fred --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---