Exemplo n.º 1
0
def load_jobs(jq):

    # w: open for writing, truncating the file first
    # b: binary mode
    # r: open for reading (default)
    with FILE.open(mode='rb') as fp:
        while True:
            try:
                # next_t, data, state = pickle.load(fp)
                next_t = pickle.load(fp)
                state = pickle.load(fp)
                data = pickle.load(fp)
            except EOFError:
                break  # loaded all jobs

            # New object with the same data
            job = Job(**{var: val for var, val in zip(JOB_DATA, data)})

            # Restore the state it had
            for var, val in zip(JOB_STATE, state):
                attribute = getattr(job, var)
                getattr(attribute, 'set' if val else 'clear')()

            job.job_queue = jq

            next_t -= time()  # convert from absolute to relative time

            jq._put(job, next_t)
Exemplo n.º 2
0
def load_jobs_from_bytes(jq, pickle_buffer: bytes):
    next_t, data, state = pickle.loads(pickle_buffer)
    # New object with the same data
    job = Job(**{var: val for var, val in zip(JOB_DATA, data)})

    # Restore the state it had
    for var, val in zip(JOB_STATE, state):
        attribute = getattr(job, var)
        getattr(attribute, 'set' if val else 'clear')()

    job.job_queue = jq

    next_t -= time()  # convert from absolute to relative time

    jq._put(job, next_t)
Exemplo n.º 3
0
def load_jobs(jq):
    with open(JOBS_PICKLE_PATH, 'rb') as fp:
        while True:
            try:
                next_t, data, state = pickle.load(fp)
            except EOFError:
                break  # loaded all jobs

            # New object with the same data
            job = Job(**{var: val for var, val in zip(JOB_DATA, data)})

            # Restore the state it had
            for var, val in zip(JOB_STATE, state):
                attribute = getattr(job, var)
                getattr(attribute, 'set' if val else 'clear')()

            job.job_queue = jq
            next_t -= time()  # convert from absolute to relative time
            jq._put(job, next_t)
Exemplo n.º 4
0
def load_jobs(jq):
    while True:
        if redis_pool.exists('pickle'):
            next_t, data, state = pickle.loads(redis_pool.lpop('pickle'))
        else:
            break  # loaded all jobs

        # New object with the same data
        job = Job(**{var: val for var, val in zip(JOB_DATA, data)})

        # Restore the state it had
        for var, val in zip(JOB_STATE, state):
            attribute = getattr(job, var)
            getattr(attribute, 'set' if val else 'clear')()

        job.job_queue = jq
        next_t -= time()  # convert from absolute to relative time

        jq._put(job, next_t)
Exemplo n.º 5
0
def load_jobs(jq):
    with open(get_path('job_pickle_db'), 'rb') as fp:
        while True:
            try:
                next_t, data, state = pickle.load(fp)
            except EOFError:
                break  # Loaded all job tuples

            # New object with the same data
            job = Job(**{var: val for var, val in zip(JOB_DATA, data)})

            # Restore the state it had
            for var, val in zip(JOB_STATE, state):
                attribute = getattr(job, var)
                getattr(attribute, 'set' if val else 'clear')()

            job.job_queue = jq

            next_t -= time()  # convert from absolute to relative time

            jq._put(job, next_t)
            logger.info(f'@@@@ {job.name} RESTORED, interval={job.interval}')