开发者

ruby on rails + bash script, please help!

开发者 https://www.devze.com 2023-03-18 03:55 出处:网络
In terminal i write: ruby lib/scripts/script.rb In on script.rb I have 2 scripts... script.rb require \'config/environment\'

In terminal i write: ruby lib/scripts/script.rb

In on script.rb I have 2 scripts...

script.rb

    require 'config/environment'

    #first script
#notifier user that question deadline is over and show statistics
inquiry.each do |i|   
    question          = i.question 

    #respondent        = Respondent.find(:all, :conditions => ["id = (?)", i.respondent_id])
    respondent        = i.respondent

    #Notifier.deliver_deadline_notification(inquiry, user, question, respondent)
     Notifier.deliver_statistics_notification(inquiry, question, user, respondent)

    #respondent        = Respondent.find(:all, :conditions => ["id = (?)", i.respondent_id])
    #respondents.each do |r|         
    #end
end

-----------------

    #second script
respondents       = Respondent.find(:all)
inquiries         = Inquiry.find(:all, :conditions => ["is_answered = 0 AND respondent_id = (?)", respondents])
#respondents       = Respondent.find(:first, :conditions => ["id = (?)", inquiries])

questions       = Question.find(:all) 
qdead           = questions.deadline

dead_line_date  = qdead - 1.days - 0.minutes - 0.seconds 
get_time_now    = Time.now.strftime('%m/%d/%Y') 

I have those 2 scripts (1 script do something ,and second is another) in one rb file. My question is... How do I can write in console to launch 1st script and 2nd script simultaneously? I know i use some AGVG ? But How?

Thank you very much!

UPD: using cron i wrote:

0 0 * * * /usr/bin/rails-run-script myproject script oncoming

0 1 * * * /usr/bin/rails-run-script myproject script missed

d

oncoming and missed - arguments. How i can deprecate them in my script.rb. How script will know that Im usin开发者_运维知识库g missed or oncoming ?


If I get your question right, what you have is a script that behaves differently based on the command line argument you pass to the script, right?

So script missed does a and script oncoming does something else.

If it's really just as simple as that, you could simply decide on ARGV.first.

case ARGV.first 
when "oncoming"
  # your "oncoming" logic (preferably wrapped in a method call) here
when "missed"
  # your "missed" logic
else
  $stderr.puts "Call the script with either missed or oncoming" 
  exit 1
end

however, if you want to do anything slightly more complex with options, I'd highly recommend using optparse.rb which is included in rubys stdlib (http://ruby-doc.org/stdlib/libdoc/optparse/rdoc/index.html)

0

精彩评论

暂无评论...
验证码 换一张
取 消