Ejemplo n.º 1
0
def rules(cube,
          scheduler_type='minutes',
          scheduler_interval=59,
          dashboard=None):
    if scheduler_type:
        scheduler_type = cube.get('scheduler_type', 'minutes')
    if scheduler_interval:
        scheduler_interval = cube.get('scheduler_interval', 59)

    log_it("START REGISTER", "bin-scheduler")
    log_it("cube: {}".format(cube.get('slug')), "bin-scheduler")
    log_it("type: {}".format(scheduler_type), "bin-scheduler")
    log_it("interval: {}".format(scheduler_interval), "bin-scheduler")
    log_it("END REGISTER", "bin-scheduler")

    t = {}
    if scheduler_type == 'minutes':
        env = schedule.every(int(scheduler_interval))
        t = env.minutes
    elif scheduler_type == 'hour':
        env = schedule.every()
        t = env.hour
    elif scheduler_type == 'day':
        env = schedule.every()
        t = env.day
    else:
        return False

    jobn = cube.get("slug")
    try:
        t.do(job, slug=cube.get('slug'))
        if dashboard:
            jobn = u"{}-{}".format(cube.get("slug"), dashboard)
        onrun[jobn] = env
        register.append(jobn)
        if cube.get('run') != 'run':
            run(cube.get('slug'))
    except Exception, e:
        if jobn in register:
            register.remove(jobn)
        if onrun.get(jobn):
            del onrun[jobn]
        log_it("ERROR {}: {}".format(cube.get('slug'), e))
Ejemplo n.º 2
0
def rules(cube, scheduler_type='minutes', scheduler_interval=59,
          dashboard=None):
    if scheduler_type:
        scheduler_type = cube.get('scheduler_type', 'minutes')
    if scheduler_interval:
        scheduler_interval = cube.get('scheduler_interval', 59)

    log_it("START REGISTER", "bin-scheduler")
    log_it("cube: {}".format(cube.get('slug')), "bin-scheduler")
    log_it("type: {}".format(scheduler_type), "bin-scheduler")
    log_it("interval: {}".format(scheduler_interval), "bin-scheduler")
    log_it("END REGISTER", "bin-scheduler")

    t = {}
    if scheduler_type == 'minutes':
        env = schedule.every(int(scheduler_interval))
        t = env.minutes
    elif scheduler_type == 'hour':
        env = schedule.every()
        t = env.hour
    elif scheduler_type == 'day':
        env = schedule.every()
        t = env.day
    else:
        return False

    jobn = cube.get("slug")
    try:
        t.do(job, slug=cube.get('slug'))
        if dashboard:
            jobn = u"{}-{}".format(cube.get("slug"), dashboard)
        onrun[jobn] = env
        register.append(jobn)
        if cube.get('run') != 'run':
            run(cube.get('slug'))
    except Exception, e:
        if jobn in register:
            register.remove(jobn)
        if onrun.get(jobn):
            del onrun[jobn]
        log_it("ERROR {}: {}".format(cube.get('slug'), e))
Ejemplo n.º 3
0
def job(slug):
    log_it("START JOB: {}".format(slug), "bin-scheduler")
    run(slug)
    log_it("END JOB: {}".format(slug), "bin-scheduler")
Ejemplo n.º 4
0
        onrun[jobn] = env
        register.append(jobn)
    except Exception, e:
        log_it("ERROR {}: {}".format(cube.get('slug'), e))

    return True


mongo = MongoPlugin(
    uri=conf("mongodb")["uri"],
    db=conf("mongodb")["db"],
    json_mongo=True).get_mongo()

for cube in mongo['cube'].find({'scheduler_status': True}):
    rules(cube)
    run(cube['slug'])

for dashboard in mongo['dashboard'].find({'scheduler_status': True}):
    elements = [e['id'] for e in dashboard['element']]
    for e in elements:
        element = mongo['element'].find_one({'slug': e})
        cube = mongo['cube'].find_one({'slug': element['cube']})
        rules(cube, dashboard['scheduler_type'],
              dashboard['scheduler_interval'])
        run(cube['slug'])

while True:
    for cube in mongo['cube'].find({'scheduler_status': True}):
        if cube['slug'] not in register:
            rules(cube)
Ejemplo n.º 5
0
        "slug": "demo",
        "name": "Demo"
    }
}

headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
print 'CREATE USER admin'
r = requests.post(url_api.get('user'), data=json.dumps(data.get('user')),
                  headers=headers)
print 'CREATE connection'
r = requests.post(url_api.get('connection'),
                  data=json.dumps(data.get('connection')),
                  headers=headers)
print 'CREATE cube'
for cb in data.get('cube'):
    r = requests.post(url_api.get('cube'), data=json.dumps(cb),
                      headers=headers)
    print 'RUNNING cube {}'.format(cb.get('slug'))
    run(cb.get('slug'))

print 'CREATE element'
for el in data.get('element'):
    print '--> {}'.format(el.get('name'))
    r = requests.post(url_api.get('element'), data=json.dumps(el),
                      headers=headers)

print 'CREATE dashboard'
r = requests.post(url_api.get('dashboard'),
                  data=json.dumps(data.get('dashboard')),
                  headers=headers)
Ejemplo n.º 6
0
def job(slug):
    log_it("START JOB: {}".format(slug), "bin-scheduler")
    run(slug)
    log_it("END JOB: {}".format(slug), "bin-scheduler")
Ejemplo n.º 7
0
            jobn = u"{}-{}".format(cube.get("slug"), dashboard)
        onrun[jobn] = env
        register.append(jobn)
    except Exception, e:
        log_it("ERROR {}: {}".format(cube.get('slug'), e))

    return True


mongo = MongoPlugin(uri=conf("mongodb")["uri"],
                    db=conf("mongodb")["db"],
                    json_mongo=True).get_mongo()

for cube in mongo['cube'].find({'scheduler_status': True}):
    rules(cube)
    run(cube['slug'])

for dashboard in mongo['dashboard'].find({'scheduler_status': True}):
    elements = [e['id'] for e in dashboard['element']]
    for e in elements:
        element = mongo['element'].find_one({'slug': e})
        cube = mongo['cube'].find_one({'slug': element['cube']})
        rules(cube, dashboard['scheduler_type'],
              dashboard['scheduler_interval'])
        run(cube['slug'])

while True:
    for cube in mongo['cube'].find({'scheduler_status': True}):
        if cube['slug'] not in register:
            rules(cube)