Skip to content

Commit

Permalink
added hourly/daily/monthly
Browse files Browse the repository at this point in the history
  • Loading branch information
David Hayes committed Nov 6, 2011
1 parent 4436d49 commit bcb76e5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
3 changes: 3 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ <h1>Flakey Error-prone Server</h1>
<li><a href="/err/404">/err/404</a> will throw a 404 error every time. Valid choices are
400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 500, 501, 502, 503, 504 and 505</li>
<li>So for example <a href="/2/401">/2/401</a> will throw a 401 error 50% of the time.</li>
<li><a href="/hour">/hour</a> will error every other hour.</li>
<li><a href="/day">/day</a> will error every other day.</li>
<li><a href="/month">/month</a> will error every other month.</li>
</ul>

<p>That's about it, it's hosted on <a href="http://code.google.com/appengine">Google App Engine</a> source is up at <a href="https://github.com/eurica/FEPServer">github.com/eurica/FEPServer</a>
Expand Down
20 changes: 15 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
from google.appengine.ext import webapp
from google.appengine.ext.webapp import util
import random
from datetime import datetime

class MainHandler(webapp.RequestHandler):
errors = [400,401,402,403,404,405,406,407,408,409,410,411,412,413,414,415,416,500,501,502,503,504,505]
def get(self):
opts = self.request.path.split('/')

try:
odds = int(opts[1])
except:
odds = 1
odds = 1
if(opts.count>1):
if( (opts[1]=="hour") & (datetime.utcnow().hour % 2) ):
odds = -1
elif( (opts[1]=="day") & (datetime.utcnow().day % 2) ):
odds = -1
elif( (opts[1]=="month") & (datetime.utcnow().month % 2) ):
odds = -1
else:
try:
odds = int(opts[1])
except:
odds = 1

try:
err = 500;
Expand All @@ -19,7 +29,7 @@ def get(self):
except:
err = random.choice(self.errors)

if( random.randint(1, odds) == 1 ):
if( (odds > 0) & (random.randint(1, max(odds,1)) == 1) ):
self.response.set_status(err)
self.response.out.write("<h1>Error: " + str(err) + "</h1><br>\n")
self.response.out.write('I am indeed amazed when I consider how weak my mind is and how prone to error. ')
Expand Down

0 comments on commit bcb76e5

Please sign in to comment.