def start_manager():
    if get_manager_processes():
        raise ManagerError('Manager is already running.')

    directory = pathlib.Path().resolve()
    stateless_manager_path = os.path.join(directory, 'stateless-manager.exe')
    if not os.path.exists(stateless_manager_path):
        raise FileNotFoundError('Failed to find stateless-manager.')
    manager_log_file_path = os.path.join(directory, 'manager.log')
    manager_log_file = open(manager_log_file_path, 'a')

    chia_location, log_directory, jobs, manager_check_interval, max_concurrent, progress_settings, \
        notification_settings, debug_level, view_settings = get_config_info()

    extra_args = []

    args = [stateless_manager_path] + extra_args
    start_process(args=args, log_file=manager_log_file)
    time.sleep(1)
    if not get_manager_processes():
        print('warning: chia plotter not found')

    send_notifications(
        title='Plot manager started',
        body=f'Plot Manager has started on {socket.gethostname()}...',
        settings=notification_settings,
    )
    print('Plot Manager has started...')
Esempio n. 2
0
def check_log_progress(jobs, running_work, progress_settings,
                       notification_settings, view_settings,
                       instrumentation_settings, backend):
    for pid, work in list(running_work.items()):
        logging.info(f'Checking log progress for PID: {pid}')
        if not work.log_file:
            continue
        f = open(work.log_file, 'r')
        data = f.read()
        f.close()

        line_count = (data.count('\n') + 1)

        progress = get_progress(line_count=line_count,
                                progress_settings=progress_settings,
                                backend=backend)

        phase_times, phase_dates = get_phase_info(
            data,
            view_settings,
            backend=backend,
            start_time=work.datetime_start)
        current_phase = 1
        if phase_times:
            current_phase = max(phase_times.keys()) + 1
        work.phase_times = phase_times
        work.phase_dates = phase_dates
        work.current_phase = current_phase
        work.progress = f'{progress:.2f}%'

        if psutil.pid_exists(
                pid) and 'renamed final file from ' not in data.lower():
            logging.info(f'PID still alive: {pid}')
            continue

        logging.info(f'PID no longer alive: {pid}')
        for job in jobs:
            if not job or not work or not work.job:
                continue
            if job.name != work.job.name:
                continue
            logging.info(f'Removing PID {pid} from job: {job.name}')
            if pid in job.running_work:
                job.running_work.remove(pid)
            job.total_running -= 1
            job.total_completed += 1
            increment_plots_completed(
                increment=1,
                job_name=job.name,
                instrumentation_settings=instrumentation_settings)

            send_notifications(
                title='Plot Completed',
                body=f'You completed a plot on {socket.gethostname()}!',
                settings=notification_settings,
            )
            break
        del running_work[pid]
Esempio n. 3
0
def start_manager():
    if get_manager_processes():
        raise ManagerError('Manager is already running.')

    directory = pathlib.Path().resolve()
    stateless_manager_path = os.path.join(directory, 'stateless-manager.py')
    if not os.path.exists(stateless_manager_path):
        raise FileNotFoundError('Failed to find stateless-manager.')
    debug_log_file_path = os.path.join(directory, 'debug.log')
    debug_log_file = open(debug_log_file_path, 'a')
    python_file_path = sys.executable

    chia_location, log_directory, config_jobs, manager_check_interval, max_concurrent, max_for_phase_1, \
        minimum_minutes_between_jobs, progress_settings, notification_settings, debug_level, view_settings, \
        instrumentation_settings = get_config_info()

    load_jobs(config_jobs)

    test_configuration(chia_location=chia_location,
                       notification_settings=notification_settings,
                       instrumentation_settings=instrumentation_settings)

    extra_args = []
    if is_windows():
        pythonw_file_path = '\\'.join(
            python_file_path.split('\\')[:-1] + ['pythonw.exe'])
    else:
        pythonw_file_path = '\\'.join(
            python_file_path.split('\\')[:-1] + ['python &'])
        extra_args.append('&')
    if os.path.exists(pythonw_file_path):
        python_file_path = pythonw_file_path

    args = [python_file_path, stateless_manager_path] + extra_args
    start_process(args=args, log_file=debug_log_file)
    time.sleep(3)
    if not get_manager_processes():
        raise ManagerError(
            'Failed to start Manager. Please look at debug.log for more details on the error. It is in the same folder as manager.py.'
        )

    send_notifications(
        title='Plot manager started',
        body=f'Plot Manager has started on {socket.gethostname()}...',
        settings=notification_settings,
    )
    print('Plot Manager has started...')
Esempio n. 4
0
def stop_manager():
    chia_location, log_directory, config_jobs, manager_check_interval, max_concurrent, max_for_phase_1, \
        minimum_minutes_between_jobs, progress_settings, notification_settings, debug_level, view_settings, \
        instrumentation_settings = get_config_info()
    processes = get_manager_processes()
    if not processes:
        print("No manager processes were found.")
        return
    for process in processes:
        try:
            process.terminate()
        except psutil.NoSuchProcess:
            pass
    if get_manager_processes():
        raise TerminationException("Failed to stop manager processes.")

    send_notifications(
        title='Plot manager stopped',
        body=f'Plot Manager has stopped on {socket.gethostname()}...',
        settings=notification_settings,
    )
    print("Successfully stopped manager processes.")