Mercurial > repos > icfp2013
comparison src/solver.tp @ 49:8409af16d6e5
Sleep for 20 seconds when we receive a 429 response
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 11 Aug 2013 04:35:02 -0700 |
parents | 855c05c9cae1 |
children | f4399a22a704 |
comparison
equal
deleted
inserted
replaced
48:855c05c9cae1 | 49:8409af16d6e5 |
---|---|
136 } | 136 } |
137 root | 137 root |
138 } | 138 } |
139 | 139 |
140 solve:withAuth:andInfo:andProg <- :progId :authKey :info :prog { | 140 solve:withAuth:andInfo:andProg <- :progId :authKey :info :prog { |
141 start <- os time | 141 statusCode <- 429 |
142 resp <- (requests evalId: progId (info allInputs)) sendWithKey: authKey | 142 resp <- false |
143 end <- os time | 143 start <- 0 |
144 if: (end - start) < 4 { | 144 end <- 0 |
145 os sleep: (4 - (end - start)) | 145 while: { statusCode = 429} do: { |
146 start <- os time | |
147 resp <- (requests evalId: progId (info allInputs)) sendWithKey: authKey | |
148 end <- os time | |
149 if: (resp status) = "ok" { | |
150 statusCode <- 200 | |
151 if: (end - start) < 4 { | |
152 os sleep: (4 - (end - start)) | |
153 } | |
154 } else: { | |
155 statusCode <- resp httpCode | |
156 if: statusCode = 429 { | |
157 print: "API is pissed, waiting 20 seconds...\n" | |
158 os sleep: 20 | |
159 } | |
160 } | |
146 } | 161 } |
147 if: (resp status) = "ok" { | 162 if: (resp status) = "ok" { |
148 print: "Start: " . (string: start) . ", End: " . (string: start) . "Duration: " . (string: end - start) . "\n" | 163 print: "Start: " . (string: start) . ", End: " . (string: start) . "Duration: " . (string: end - start) . "\n" |
149 matches <- info findMatches: (resp outputs) at: 0 | 164 matches <- info findMatches: (resp outputs) at: 0 |
150 noSuccess <- true | 165 noSuccess <- true |
178 matches <- filtered | 193 matches <- filtered |
179 if: (matches length) = 0 { | 194 if: (matches length) = 0 { |
180 print: "None of our programs actually matched 0x" . (hex: failOutput) ." with input 0x" . (hex: failInput) ." :(\n" | 195 print: "None of our programs actually matched 0x" . (hex: failOutput) ." with input 0x" . (hex: failInput) ." :(\n" |
181 } | 196 } |
182 } else: { | 197 } else: { |
183 print: "Got message: " . (gresp message) . ", moving on\n" | 198 if: (gresp httpCode) = 429 { |
184 cur <- cur + 1 | 199 print: "API is pissed, waiting 20 seconds...\n" |
200 os sleep: 20 | |
201 } else: { | |
202 print: "Got message: " . (gresp message) . ", moving on\n" | |
203 cur <- cur + 1 | |
204 } | |
185 } | 205 } |
186 } | 206 } |
187 } | 207 } |
188 } else: { | 208 } else: { |
189 print: resp | 209 print: resp |