<commit_before>#! /usr/bin/env python

from flask import Flask, make_response, request
from rq import Queue
from load_redis import configure_redis
from jobs import aggregate
import os
import json
import logging

app = Flask(__name__)
env = os.getenv('FLASK_ENV', 'production')
#30 mins - http://python-rq.org/docs/results/
q = Queue('default', connection=configure_redis(env), default_timeout=1800)
apis = {
    'development': "http://"+str(os.getenv('HOST_IP', '172.17.42.1'))+":3000",
    'staging': "https://panoptes-staging.zooniverse.org",
    'production': "https://panoptes.zooniverse.org"
}

api_root = apis[env]

@app.route('/',methods=['POST'])
def start_aggregation():
    try:
        body = request.get_json()
        project = body['project_id']
        href = body['medium_href']
        metadata = body['metadata']
        token = body['token']
        q.enqueue(aggregate, project, token, api_root+"/api"+href, metadata, env)
        resp = make_response(json.dumps({'queued': True}), 200)
        resp.headers['Content-Type'] = 'application/json'
        return resp
    except KeyError:
        resp = make_response(json.dumps({'error': [{'messages': "Missing Required Key"}]}), 422)
        resp.headers['Content-Type'] = 'application/json'
        return resp

@app.before_first_request
def setup_logging():
    if not app.debug:
        import logging
        handler = logging.StreamHandler()<commit_msg>upping time limit to 2 hours until I can get things optimized<commit_after>#! /usr/bin/env python

from flask import Flask, make_response, request
from rq import Queue
from load_redis import configure_redis
from jobs import aggregate
import os
import json
import logging

app = Flask(__name__)
env = os.getenv('FLASK_ENV', 'production')
#30 mins - http://python-rq.org/docs/results/
q = Queue('default', connection=configure_redis(env), default_timeout=7200)
apis = {
    'development': "http://"+str(os.getenv('HOST_IP', '172.17.42.1'))+":3000",
    'staging': "https://panoptes-staging.zooniverse.org",
    'production': "https://panoptes.zooniverse.org"
}

api_root = apis[env]

@app.route('/',methods=['POST'])
def start_aggregation():
    try:
        body = request.get_json()
        project = body['project_id']
        href = body['medium_href']
        metadata = body['metadata']
        token = body['token']
        q.enqueue(aggregate, project, token, api_root+"/api"+href, metadata, env)
        resp = make_response(json.dumps({'queued': True}), 200)
        resp.headers['Content-Type'] = 'application/json'
        return resp
    except KeyError:
        resp = make_response(json.dumps({'error': [{'messages': "Missing Required Key"}]}), 422)
        resp.headers['Content-Type'] = 'application/json'
        return resp

@app.before_first_request
def setup_logging():
    if not app.debug:
        import logging
        handler = logging.StreamHandler()
{'fraction_non_alphanumeric': 0.14955203308063406, 'fraction_numerical': 0.016884906960716747, 'mean_word_length': 3.728013029315961, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4693147', 'n_tokens_mistral': 951, 'n_tokens_neox': 909, 'n_words': 210}