Пример #1
0
def process_doc(redis_server, json_data, compressed_file, destination):
    """
    Main document function, called by the server to check and
    save document files returned from the client
    """
    if redis_server.does_job_exist_in_progress(json_data['job_id']):
        temp_directory = tempfile.mkdtemp()
        temp_directory_path = str(temp_directory + '/')

        # Unzip the zipfile and then remove the tar file
        # and create a list of all the files in the directory
        file_list, temp_directory_path = get_file_list(compressed_file,
                                                       temp_directory_path,
                                                       json_data['client_id'])
        break_check = False
        for file in file_list:
            job_needs_renew = check_if_document_needs_renew(
                file, json_data, temp_directory_path)
            if job_needs_renew is True:
                redis_server.renew_job(json_data['job_id'])
                break_check = True
                break
        if break_check is False:
            save_all_files_locally(file_list, temp_directory_path, destination)
            dc.remove_job_from_progress(redis_server, json_data)
Пример #2
0
def test_remove_doc_from_progress():
    redis_server = make_database()

    json_data = json.dumps({'job_id': '1', 'type': 'doc',
                            'client_id': 'Alex', 'VERSION': '0.0.0'})
    redis_server.add_to_progress(json_data)
    json_data = json.loads(json_data)

    dc.remove_job_from_progress(redis_server, json_data)
    progress = redis_server.get_all_items_in_progress()
    assert len(progress) == 0
Пример #3
0
def process_docs(redis_server, json_data, compressed_file, path):
    """
    Main documents function, called by the server to compile list of
    document jobs and add them to the "queue" queue
    :param json_data: the json data for the jobs
    :param compressed_file: the zipfile containing the client's log
    :return:
    """
    if redis_server.does_job_exist_in_progress(json_data['job_id']) is True:
        save_client_log(json_data['client_id'], compressed_file)
        workfile_length_passed = check_workfile_length(json_data)
        file_type_is_docs = json_data['type'] == 'docs'

        if workfile_length_passed and file_type_is_docs:
            json_data = check_document_exists(json_data, path)
            add_document_job_to_queue(redis_server, json_data)
            dc.remove_job_from_progress(redis_server, json_data)
        else:
            redis_server.renew_job(json_data['job_id'])