-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstatus.rb
100 lines (84 loc) · 2.47 KB
/
status.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# Represents the online/offline status of a link.
class Status
def initialize
@status = :resolving
@message = nil
@should_probe = true
end
# Set it to offline.
def offline!(reason = nil)
@status = :offline
@message = reason
@should_probe = false
@retry_nonrecursive = false
end
# Set it to online.
def online!
@status = :online
@message = nil
@should_probe = true
@retry_nonrecursive = false
end
# Set it to error.
def error!(reason = nil, should_probe = false, retry_nonrecursive = false)
@status = :error
@message = reason
@should_probe = should_probe
@retry_nonrecursive = retry_nonrecursive
end
# Returns true if the link was reported as bad by plowlist
# but should still be probed by plowprobe
def should_probe?
@should_probe
end
# Returns true if the link is currently being resolved.
def resolving?
@status == :resolving
end
# Returns true if the link is definitely online.
def online?
return @status == :online
end
# Returns true if the link is definitely offline.
def offline?
return @status == :offline
end
# Returns true if an error occurred during resolution.
def error?
return @status == :error
end
# Returns true if a recursive call should be retried
# non-recursively.
def retry_nonrecursive?
@retry_nonrecursive
end
def to_s
str = @status.to_s
str += " (#{@message})" if @message
return str
end
# Creates a new status from a plowshare status value.
def self.from_plowshare(plowshare_status)
status = Status.new
return unless plowshare_status
normalized_status = plowshare_status % 100
case normalized_status
when 0 then status.online!
when 1 then status.error!("module out of date", true)
when 2 then status.error!("not supported", true)
when 3 then status.error!("network error", true)
when 3 then status.error!("login failed")
when 5, 6 then status.error!("timeout", true)
when 7 then status.error!("captcha error")
when 8 then status.error!("bug in the module", true)
when 10 then status.offline!("temporarily unavailable")
when 11 then status.error!("needs password")
when 12 then status.error!("requires authentication")
when 13 then status.offline!
when 14 then status.error!("file too big")
when 15 then status.error!("bug in plowui", true, true)
else status.error!("unknown error code #{plowshare_status}")
end
return status
end
end