Created
September 9, 2010 19:26
-
-
Save jzellman/572390 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Company | |
# Returns the latest past scan or nil if one does not exist | |
# | |
def last_scan(start_date = nil, end_date=Time.now) | |
conditions = if start_date | |
['status in ? AND scheduled_at IS NOT NULL and scheduled_at > ? AND scheduled_at < ?', | |
Status.finished_states, start_date, end_date] | |
else | |
['status in ? AND scheduled_at IS NOT NULL AND scheduled_at < ?', | |
Status.finished_states, end_date] | |
end | |
scans.find(:first, :conditions => conditions, :order => "scheduled_at DESC") | |
end | |
def latest_scan_in_3_months | |
last_scan(3.months.ago, Time.now) | |
end | |
end | |
class Scan | |
module Status | |
RUNNING = 'R' | |
PAUSED = 'H' | |
COMPLETED = 'C' | |
STOPPED = 'P' # ??? | |
HALTED = 'K' # ??? | |
FAILED = 'F' # ??? | |
SCHEDULED = 'S' | |
end | |
def self.finished_states | |
[Status::COMPLETED, Status::FAILED, Status::STOPPED] | |
end | |
# is the scan in a state that is not running or scheduled? | |
# returns true if status is completed, failed, or stopped | |
# | |
def is_completed? | |
self.class.finished_states.include?(status) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment