예제 #1
0
def build_executable_file(job_id, job_step, protocol, workspace):
    """
    Build executable file
    :param job_id: int
    :param job_step: int
    :param protocol: str
    :param workspace: str
    :return: str, file path
    """
    from ui.tools import os_to_int
    import os
    if os_to_int() == 2:
        job_name = str(job_id) + '-' + str(job_step) + '.bat'
        script = """:: file name: %s
@echo off

cd %s
%s
""" % (job_name, workspace, protocol)
    else:
        job_name = str(job_id) + '-' + str(job_step) + '.sh'
        script = """#!/bin/bash
# file name: %s

cd %s
%s
""" % (job_name, workspace, protocol)
    file_name = os.path.join(workspace, job_name)
    file_handler = open(file_name, 'w')
    file_handler.write(script)
    file_handler.close()
    return file_name
예제 #2
0
def feedback_checkpoint(software,
                        parameter,
                        hash,
                        cpu_a,
                        cpu_b,
                        cpu_r,
                        mem_a,
                        mem_b,
                        mem_r,
                        disk_a,
                        disk_b,
                        disk_r,
                        mail=''):
    """
    Feedback checkpoint
    :param software: string, software name
    :param parameter: string, parameter
    :param hash: string, hash
    :param cpu_a: float, cpu a
    :param cpu_b: float, cpu b
    :param cpu_r: float, cpu r
    :param mem_a: float, memory a
    :param mem_b: float, memory b
    :param mem_r: float, memory r
    :param disk_a: float, disk a
    :param disk_b: float, disk b
    :param disk_r: float, disk r
    :return:
    """
    from ui.tools import os_to_int
    post_data_dict = dict()
    post_data_dict['cpu'] = get_config('env', 'cpu')
    post_data_dict['mem'] = get_config('env', 'memory')
    post_data_dict['os'] = os_to_int()
    post_data_dict['software'] = software
    post_data_dict['parameter'] = parameter
    post_data_dict['hash'] = hash
    post_data_dict['parent'] = 1
    if abs(float(cpu_r)) > 0.5:
        post_data_dict['cpu_a'] = cpu_a
        post_data_dict['cpu_b'] = cpu_b
        post_data_dict['cpu_r'] = cpu_r
    if abs(float(mem_r)) > 0.5:
        post_data_dict['mem_a'] = mem_a
        post_data_dict['mem_b'] = mem_b
        post_data_dict['mem_r'] = mem_r
    if abs(float(disk_r)) > 0.5:
        post_data_dict['disk_a'] = disk_a
        post_data_dict['disk_b'] = disk_b
        post_data_dict['disk_r'] = disk_r
    try:
        fb_url = get_config('program', 'api', 1) + '/Gate/cb_feedback'
        t = requests.post(fb_url, data=post_data_dict, timeout=3)
    except:
        pass