-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from kohkimakimoto/workerapp-example
Workerapp example
- Loading branch information
Showing
5 changed files
with
102 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export PRODUCT_NAME="hq" | ||
export PRODUCT_VERSION="1.0.0" | ||
export PRODUCT_VERSION="1.1.0" | ||
export COMMIT_HASH=`git log --pretty=format:%H -n 1` |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/usr/bin/env python | ||
from __future__ import division, print_function, absolute_import, unicode_literals | ||
try: | ||
from http.server import HTTPServer, SimpleHTTPRequestHandler | ||
except ImportError: | ||
# fallback for python2 | ||
from SimpleHTTPServer import SimpleHTTPRequestHandler | ||
from BaseHTTPServer import HTTPServer | ||
import argparse | ||
import sys | ||
|
||
# RequestHandler | ||
class RequestHandler(SimpleHTTPRequestHandler, object): | ||
def do_GET(self): | ||
# super(RequestHandler, self).do_GET()s | ||
self.send_response(200) | ||
self.send_header('Content-type', 'text/html') | ||
self.end_headers() | ||
self.wfile.write(b"It works!") | ||
|
||
def do_POST(self): | ||
rawPostData = "" | ||
length = self.headers.get('Content-Length') | ||
if (length): | ||
rawPostData = self.rfile.read(int(length)) | ||
jobId = self.headers.get('X-Hq-Job-Id') | ||
if not jobId: | ||
jobId = "unknown" | ||
|
||
print("--POST REQUEST BEGIN--") | ||
print("%s %s\n%s" % (self.command, self.path, self.headers)) | ||
print("%s" % (rawPostData)) | ||
print("--POST REQUEST END----") | ||
|
||
self.send_response(200) | ||
self.send_header('Content-type', 'text/html') | ||
self.end_headers() | ||
self.wfile.write(b"Got a job: " + jobId) | ||
|
||
# main | ||
def main(): | ||
parser = argparse.ArgumentParser( | ||
description="An example worker web app for HQ", | ||
formatter_class=argparse.RawDescriptionHelpFormatter, | ||
epilog=""" | ||
An example worker web app for HQ. | ||
""" | ||
) | ||
|
||
parser.add_argument('-H', '--host', dest="host", default="") | ||
parser.add_argument('-p', '--port', dest="port", type=int, default=8000) | ||
args = parser.parse_args() | ||
|
||
port = args.port | ||
host = args.host | ||
|
||
httpd = HTTPServer((host, port), RequestHandler) | ||
print("Serving at port", port) | ||
httpd.serve_forever() | ||
|
||
if __name__ == '__main__': main() |
This file contains 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
This file contains 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