Module: Forcast::Model::RuleEngine::PollingEngine

Extended by:
ActiveSupport::Concern
Included in:
Polling
Defined in:
lib/forcast/models/rule_engine/polling_engine.rb

Instance Method Summary collapse

Instance Method Details

#validate_duration_timeObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/forcast/models/rule_engine/polling_engine.rb', line 71

def validate_duration_time
  puts "validate_duration_time"
  polling_duration_time = self.duration_time
  polling_duration_time ||= 1
  testing_time = self.created_at + polling_duration_time.minutes
  if testing_time.to_i < Time.now.to_i
    self.update_columns(:active? => false)
    puts "Duration period expire"
    return false      
  else
    puts "Duration period still active"
    return true
  end
end

#validate_execute_timeObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/forcast/models/rule_engine/polling_engine.rb', line 52

def validate_execute_time
    puts "validate_execute_time"
  execution_time = self.review_time
  execution_time ||= 30
  last_execution = self.last_execution
  testing_time = last_execution + execution_time.second
  if testing_time.to_i > Time.now.to_i
    puts "It should not be executed"
    self.update_columns(:execute? => false)
    return false      
  else
    puts "Must be executed"
    self.update_columns(:last_execution => Time.now,
                 :execute? => true)
    return true
  end

end

#validate_send_timeObject



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/forcast/models/rule_engine/polling_engine.rb', line 86

def validate_send_time
    puts "validate_send_time"
    send_time = self.send_time
    send_time ||= 30
    last_review_send = self.last_review_send
    last_review_send ||= Time.now
    testing_time = last_review_send + send_time.second
    remain = testing_time.to_i - Time.now.to_i
  if testing_time.to_i > Time.now.to_i
      puts "Dont send yet, remains #{remain} seconds"
      self.update_columns( :last_review_send => Time.now,
                  :send? => false)
    return false      
  else
      puts "Send now"
      self.update_columns(:last_send => Time.now,
                   :send? => true)
    return true
  end

end