Database Reference
In-Depth Information
day would be confusing. The mechanism to run this handler every day is
discussed in detail later in the chapter.
Listing 8.5 : Table Creation Handler (dashboard.py)
class _CreateTableHandler(webapp2.RequestHandler):
# The get call schedules the post call to create
tables.
def get(self):
taskqueue.add(url=self.request.route.build(
self.request, [], {}))
self.response.headers['Content-Type'] = 'text/
plain'
self.response.write('ok')
# Performs the actual creation.
def post(self):
# First create required datasets.
for dataset in ['logs', 'dashboard']:
try:
bigquery.datasets().insert(
projectId=PROJECT_ID,
body={
'datasetReference': {
'datasetId': dataset
}
}).execute()
except HttpError, e:
if e.resp.status == httplib.CONFLICT:
logging.info('Dataset %s exists' % dataset)
else:
logging.error('Error: ' + str(e))
# Create daily tables for the next few days.
with open('bq/schema_log.json', 'r') as
schema_file:
schema = json.load(schema_file)
today = datetime.datetime.utcnow()
for delta in xrange(2, 5):
 
Search WWH ::




Custom Search