Exemplo n.º 1
0
def anon_worker():
    register_timer(name='anon_worker', target=anon_worker, timeout=0.5).start()

    for message in pop_messages(type='cascade response'):
        Thread(target=process, args=(message, )).start()

    for message in pop_messages(type='cascade request'):
        Thread(target=process, args=(message, )).start()
Exemplo n.º 2
0
def poll_worker():
    register_timer(name='poll_worker', target=poll_worker, timeout=0.5).start()

    ctr_set_name('uptime', int(time() - START_TIME))

    for peer in get_peers():
        if ctr_get_name('threads (polling-{0})'.format(peer['agtuuid'])) == 0:
            ctr_increment('threads (polling-{0})'.format(peer['agtuuid']))

            Thread(target=poll, args=(peer, )).start()
Exemplo n.º 3
0
def process_handle_time_out_worker(phduuid):
    try:
        if time(
        ) - process_handles[phduuid]['contact'] > PROCESS_HANDLE_TIME_OUT:
            close_process_handle(phduuid)
        else:
            register_timer(name=phduuid,
                           target=process_handle_time_out_worker,
                           args=(phduuid, ),
                           timeout=60).start()
    except:
        pass
Exemplo n.º 4
0
def ad_worker():
    rt = int(random() * 30.0)

    register_timer(name='ad_worker', target=ad_worker, timeout=rt).start()

    age_routes(rt)

    for peer in get_peers():
        if ctr_get_name('threads (advertising-{0})'.format(
                peer['agtuuid'])) == 0:
            ctr_increment('threads (advertising-{0})'.format(peer['agtuuid']))

            Thread(target=advertise, args=(peer, )).start()
Exemplo n.º 5
0
def file_handle_time_out_worker(fhduuid):
    try:
        if time() - file_handles[fhduuid]['contact'] > FILE_HANDLE_TIME_OUT:
            close_file_handle(fhduuid)
        else:
            register_timer(
                name=fhduuid,
                target=file_handle_time_out_worker,
                args=(fhduuid,),
                timeout=60
            ).start()
    except:
        pass
Exemplo n.º 6
0
def worker():
    register_timer(name='message_worker', target=worker, timeout=60).start()

    message_lock.acquire()

    messages = Collection('messages')

    for message in messages.find():
        try:
            if time() - message.object['timestamp'] > MESSAGE_TIMEOUT:
                message.destroy()

                ctr_increment('messages expired')
                ctr_decrement('messages queued')
        except:
            message.destroy()

    message_lock.release()
Exemplo n.º 7
0
def process_sync(command, timeout=10):
    if type(command) == type([]):
        shell = False
    else:
        shell = True

    process = Popen(command, stdout=PIPE, stderr=PIPE, shell=shell)

    kill_process = lambda p: p.kill()

    timer = register_timer(name=f'process-{time()}',
                           target=kill_process,
                           args=(process, ),
                           timeout=timeout)

    try:
        timer.start()
        process_output_buffer, process_stderr_buffer = process.communicate()
    finally:
        timer.cancel()

    return process.returncode, process_output_buffer, process_stderr_buffer
Exemplo n.º 8
0
def worker():
    register_timer(name='cascade_worker', target=worker, timeout=60).start()

    prune()
Exemplo n.º 9
0
def worker():
    global last_worker_time

    collection = SQLCollection('scripts')

    for scruuid in collection.list_objuuids():
        try:
            script = collection.get_object(scruuid)

            if 'enabled' not in script.object:
                script.object['enabled'] = False
                script.set()

            if 'silent' not in script.object:
                script.object['silent'] = False
                script.set()

            if 'seconds' not in script.object:
                script.object['seconds'] = '0'
                script.set()

            if 'minutes' not in script.object:
                script.object['minutes'] = '*'
                script.set()

            if 'hours' not in script.object:
                script.object['hours'] = '*'
                script.set()

            if 'dayofmonth' not in script.object:
                script.object['dayofmonth'] = '*'
                script.set()

            if 'dayofweek' not in script.object:
                script.object['dayofweek'] = '*'
                script.set()

            if 'year' not in script.object:
                script.object['year'] = '*'
                script.set()

            if 'body' not in script.object:
                script.object['body'] = ''
                script.set()

            if script.object['enabled'] in (True, 'true'):
                for t in range(int(last_worker_time), int(time())):
                    now = datetime.fromtimestamp(t).now()
                    if (eval_cron_field(script.object['seconds'], now.second)
                            and eval_cron_field(script.object['minutes'],
                                                now.minute) and
                            eval_cron_field(script.object['hours'], now.hour)
                            and eval_cron_field(script.object['dayofmonth'],
                                                now.day)
                            and eval_cron_field(script.object['dayofweek'],
                                                now.weekday()) and
                            eval_cron_field(script.object['year'], now.year)):
                        queue(scruuid)
                        break
        except:
            if script.object['silent'] in (False, 'false'):
                script = collection.get_object(scruuid)
                script.object['status'] = 1
                script.object['stdout'] = ''
                script.object['stderr'] = str(traceback.format_exc())
                script.set()

    last_worker_time = time()

    register_timer(name='script_worker', target=worker, timeout=1).start()
Exemplo n.º 10
0
def worker():
    global last_worker_time

    collection = SQLCollection('crons')

    for cronuuid in collection.list_objuuids():
        try:
            cron = collection.get_object(cronuuid)

            if 'enabled' not in cron.object:
                cron.object['enabled'] = False
                cron.set()

            if 'minutes' not in cron.object:
                cron.object['minutes'] = '*'
                cron.set()

            if 'hours' not in cron.object:
                cron.object['hours'] = '*'
                cron.set()

            if 'dayofmonth' not in cron.object:
                cron.object['dayofmonth'] = '*'
                cron.set()

            if 'dayofweek' not in cron.object:
                cron.object['dayofweek'] = '*'
                cron.set()

            if 'year' not in cron.object:
                cron.object['year'] = '*'
                cron.set()

            if 'timeout' not in cron.object:
                cron.object['timeout'] = 60
                cron.set()

            if 'command' not in cron.object:
                cron.object['command'] = ''
                cron.set()

            if cron.object['enabled'] in (True, 'true'):
                for t in range(int(last_worker_time), int(time()), 60):
                    now = datetime.fromtimestamp(t).now()
                    if (eval_cron_field(cron.object['minutes'], now.minute)
                            and eval_cron_field(cron.object['hours'], now.hour)
                            and eval_cron_field(cron.object['dayofmonth'],
                                                now.day)
                            and eval_cron_field(cron.object['dayofweek'],
                                                now.weekday()) and
                            eval_cron_field(cron.object['year'], now.year)):
                        queue(cronuuid)
                        break
        except:
            cron = collection.get_object(cronuuid)
            cron.object['status'] = 1
            cron.object['stdout b64data'] = b64encode(''.encode()).decode()
            cron.object['stderr b64data'] = b64encode(
                str(traceback.format_exc()).encode()).decode()
            cron.set()

    last_worker_time = time()

    register_timer(name='cron_worker', target=worker, timeout=60).start()