-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
79 lines (59 loc) · 2.43 KB
/
app.py
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
from flask import Flask
from flask.ext.pymongo import PyMongo
from bson.json_util import dumps
from utils import convert_period_job, convert_job_records
from bson.timestamp import Timestamp
app = Flask('elric')
mongo = PyMongo(app)
"""
db.elric_jobs.aggregate([{$project:{date:{$concat: (Date("$next_timestamp")).toString()}}}])
cursor = mongo.db.elric_jobs.aggregate([{
'$project':{
'lastModified':{
'$dateToString': {'format':"%Y-%m-%d", 'date':"$lastModified"}
},
db.elric_jobs.aggregate([{$project:{date:{$dateToString: {format:"%Y-%m-%d", date:"$lastModified"}}}}])
"""
@app.route('/')
def index():
return "welcome elric!<br> " \
"type /period_jobs to check all period jobs info. <br>" \
"type /period_jobs/<job_id> to check specific period jobs info. <br>" \
"type /job_records to check all executed jobs' records. <br>" \
"type /job_records/<job_id> to check specific job's records."
@app.route('/period_jobs')
def all_period_jobs():
cursor = mongo.db.elric_jobs.find({}, {'serialized_job': False})
jobs = [convert_period_job(job) for job in cursor]
return dumps(jobs)
# try:
# cursor = mongo.db.elric_jobs.aggregate([{
# '$project':{
# 'lastModified':{
# '$dateToString': {'format':"%Y-%m-%d", 'date':"$lastModified"}
# },
# 'next_timestamp':{
# '$concat': (str(Timestamp('$next_timestamp', 0).as_datetime()))
# }
# }}])
#
# return dumps(cursor)
# except Exception as e:
# print e
#
@app.route('/period_jobs/<job_id>')
def specific_period_job(job_id):
job = mongo.db.elric_jobs.find_one_or_404({'_id': job_id}, {'serialized_job': False})
return dumps(convert_period_job(job))
@app.route('/job_records/<job_id>')
def all_job_records(job_id):
job = mongo.db.elric_execute_records.find_one_or_404({'_id': job_id}, {'serialized_job': False})
return dumps(convert_job_records(job))
@app.route('/job_records')
@app.route('/job_records/<page>')
def specific_job_record(page=1):
cursor = mongo.db.elric_execute_records.find({}, {'serialized_job': False})
jobs = [convert_job_records(job) for job in cursor]
return dumps(jobs)
if __name__ == "__main__":
app.run()