Пример #1
0
def run(day = None, month = None, year = None):

    # fetch 1 days worth of reports according to arguments, defaults to today

    # response object returned
    response = { 'records': [] }

    # grab configuration json file for api key
    config = tangelo.config()
    
    if config.get('apiKey') is None:
        response['error'] = 'API key is required in configuration'
        return response
   
    # connect to mongo database
    db = getDBClient(config)
    
    dayObj = datetime.datetime.now()
    if year:
        dayObj = dayObj.replace(year=int(year))
    if month:
        dayObj = dayObj.replace(month=int(month))
    if day:
        dayObj = dayObj.replace(day=int(day))

    oneDay = datetime.timedelta(days=1)

    # fill response object and return
    records = list(db.records.find({'date': {'$gte': dayObj, '$lt': dayObj + oneDay}}))

    for record in records:
        record['date'] = record['date'].isoformat()
        record.pop('_id')

    response['records'] = records
    return response
Пример #2
0
#
# RESTful service used to create, monitor and terminate celery
# tasks.
#

# Remove current directory from search path so we don't hide the really
# celery module.
sys.path = sys.path[1:]

from celery import Celery
from celery import task, current_task
from celery.result import AsyncResult
from celery import states

celery = Celery()
config = tangelo.config()
celery.conf.update(**config)

@tangelo.restful
def get(job_id, operation, **kwargs):
    job = AsyncResult(job_id, backend=celery.backend)
    if operation == 'status':
        response = {'status': job.state}
        if job.state == states.FAILURE:
            response['message'] = str(job.result)
        elif job.state == 'PROGRESS':
            response['meta'] = str(job.result)

        return response
    elif operation == 'result':
        response  = {'result': job.result}
Пример #3
0
def run():
    cfg = tangelo.config()
    return cfg["secret"]
Пример #4
0
#
# RESTful service used to create, monitor and terminate celery
# tasks.
#

# Remove current directory from search path so we don't hide the really
# celery module.
sys.path = sys.path[1:]

from celery import Celery
from celery import task, current_task
from celery.result import AsyncResult
from celery import states

celery = Celery()
config = tangelo.config()
celery.conf.update(**config)


@tangelo.restful
def get(job_id, operation, **kwargs):
    job = AsyncResult(job_id, backend=celery.backend)
    if operation == 'status':
        response = {'status': job.state}
        if job.state == states.FAILURE:
            response['message'] = str(job.result)
        elif job.state == 'PROGRESS':
            response['meta'] = str(job.result)

        return response
    elif operation == 'result':
Пример #5
0
def run():
    cfg = tangelo.config()
    return cfg["secret"]