Skip to content

Commit 03e6107

Browse files
committed
Imported from main piku repo
1 parent a55da6e commit 03e6107

11 files changed

Lines changed: 983 additions & 0 deletions

File tree

ENV

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# variables are global and can be replaced
2+
SETTING1=True
3+
SETTING2=${SETTING1}/Maybe
4+
5+
# addr:port
6+
PORT=9080
7+
BIND_ADDRESS=0.0.0.0
8+
9+
# the max number the worker will process
10+
RANGE=10
11+
12+
# worker sleep interval between prints
13+
INTERVAL=1

Procfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
wsgi: main:app
2+
worker: python worker.py
3+
clock: python clock.py

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Sample Python Application for `piku`
2+
3+
This is a simple Python app that demonstrates:
4+
5+
- HTTP port selection via the `PORT` variable (set in `ENV`)
6+
* An independent worker process (that is auto-restarted upon exit)
7+
* Another independent worker with a built-in scheduler
8+
9+
To publish this app to `piku`, clone the repository and run the following commands:
10+
11+
```bash
12+
git remote add piku piku@your_server:sample_python_app
13+
git add .
14+
git commit -a -m "initial commit"
15+
git push piku master
16+
```

clock.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from apscheduler.schedulers.blocking import BlockingScheduler
2+
from sys import stdout
3+
4+
sched = BlockingScheduler()
5+
6+
@sched.scheduled_job('interval', minutes=3)
7+
def timed_job():
8+
print('This job is run every three minutes.')
9+
stdout.flush()
10+
11+
@sched.scheduled_job('cron', day_of_week='mon-fri', hour=17)
12+
def scheduled_job():
13+
print('This job is run every weekday at 5pm.')
14+
stdout.flush()
15+
16+
print('starting scheduler')
17+
stdout.flush()
18+
sched.start()

main.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import os
2+
from bottle import default_app, route, request, view, static_file, run
3+
4+
@route("/")
5+
@view("base")
6+
def default():
7+
result = {}
8+
table = ['<table class="u-full-width"><tbody>']
9+
for k, v in sorted(os.environ.items()):
10+
table.append('<tr><th>%s</th><td>%s</td></tr>' % (k, v))
11+
table.append('</tbody></table>')
12+
result['sys_data'] = '\n'.join(table)
13+
table = ['<table class="u-full-width"><tbody>']
14+
for k, v in sorted(dict(request.environ).items()):
15+
table.append('<tr><th>%s</th><td>%s</td></tr>' % (k, v))
16+
table.append('</tbody></table>')
17+
result['req_data'] = '\n'.join(table)
18+
return result
19+
20+
@route("/<path:path>")
21+
def static(path):
22+
return static_file(path, root="static")
23+
24+
app = default_app()
25+
26+
if __name__ == '__main__':
27+
log.debug("Beginning run.")
28+
HTTP_PORT = int(environ.get('PORT', 8000))
29+
BIND_ADDRESS = environ.get('BIND_ADDRESS', '127.0.0.1')
30+
DEBUG = 'true' == environ.get('DEBUG', 'false').lower()
31+
run(host=BIND_ADDRESS, port=HTTP_PORT, debug=DEBUG)

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bottle
2+
APScheduler

0 commit comments

Comments
 (0)