def workflow_status(obj, details): """ Show the status of the workflows. """ show_colors = obj['show_color'] config_cli = obj['config'].cli if details: temp_form = '{:>{}} {:20} {:25} {:25} {:38} {}' else: temp_form = '{:>{}} {:20} {:25} {} {} {}' click.echo('\n') click.echo(temp_form.format( 'Status', 12, 'Name', 'Start Time', 'ID' if details else '', 'Job' if details else '', 'Arguments' )) click.echo('-' * (138 if details else 75)) def print_jobs(jobs, *, label='', color='green'): for job in jobs: start_time = job.start_time if job.start_time is not None else 'unknown' click.echo(temp_form.format( _style(show_colors, label, fg=color, bold=True), 25 if show_colors else 12, job.name, start_time.replace(tzinfo=pytz.utc).astimezone().strftime( config_cli['time_format']), job.workflow_id if details else '', job.id if details else '', ','.join(['{}={}'.format(k, v) for k, v in job.arguments.items()])) ) # running jobs print_jobs(list_jobs(config=obj['config'], status=JobStatus.Active, filter_by_type=JobType.Workflow), label='Running', color='green') # scheduled jobs print_jobs(list_jobs(config=obj['config'], status=JobStatus.Scheduled, filter_by_type=JobType.Workflow), label='Scheduled', color='blue') # registered jobs print_jobs(list_jobs(config=obj['config'], status=JobStatus.Registered, filter_by_type=JobType.Workflow), label='Registered', color='yellow') # reserved jobs print_jobs(list_jobs(config=obj['config'], status=JobStatus.Reserved, filter_by_type=JobType.Workflow), label='Reserved', color='yellow')
def workflow_status(obj, details): """ Show the status of the workflows. """ show_colors = obj['show_color'] temp_form = '{:>{}} {:20} {:25} {:38} {}' if details else '{:>{}} {:20} {} {} {}' click.echo('\n') click.echo( temp_form.format('Status', 12, 'Name', 'ID' if details else '', 'Job' if details else '', 'Arguments')) click.echo('-' * (113 if details else 50)) def print_jobs(jobs, *, label='', color='green'): for job in jobs: click.echo( temp_form.format( _style(show_colors, label, fg=color, bold=True), 25 if show_colors else 12, job.name, job.workflow_id if details else '', job.id if details else '', ','.join([ '{}={}'.format(k, v) for k, v in job.arguments.items() ]))) # get list of workers that consume workflows to speed up lookup workers = [ w.name for w in list_workers(config=obj['config'], filter_by_queues=[JobType.Workflow]) ] # running jobs print_jobs(list_jobs(config=obj['config'], status=JobStatus.Active, filter_by_type=JobType.Workflow, filter_by_worker=workers), label='Running', color='green') # scheduled jobs print_jobs(list_jobs(config=obj['config'], status=JobStatus.Scheduled, filter_by_type=JobType.Workflow, filter_by_worker=workers), label='Scheduled', color='blue') # registered jobs print_jobs(list_jobs(config=obj['config'], status=JobStatus.Registered, filter_by_type=JobType.Workflow, filter_by_worker=workers), label='Registered', color='yellow') # reserved jobs print_jobs(list_jobs(config=obj['config'], status=JobStatus.Reserved, filter_by_type=JobType.Workflow, filter_by_worker=workers), label='Reserved', color='yellow')
def worker_status(obj, filter_queues, details): """ Show the status of all running workers. """ show_colors = obj['show_color'] f_queues = filter_queues.split(',') if filter_queues is not None else None workers = list_workers(config=obj['config'], filter_by_queues=f_queues) if len(workers) == 0: click.echo('No workers are running at the moment.') return for ws in workers: click.echo('{} {}'.format( _style(show_colors, 'Worker:', fg='blue', bold=True), _style(show_colors, ws.name, fg='blue'))) click.echo('{:23} {}'.format(_style(show_colors, '> pid:', bold=True), ws.pid)) if details: click.echo('{:23} {}'.format( _style(show_colors, '> concurrency:', bold=True), ws.concurrency)) click.echo('{:23} {}'.format( _style(show_colors, '> processes:', bold=True), ', '.join(str(p) for p in ws.process_pids))) click.echo('{:23} {}://{}:{}/{}'.format( _style(show_colors, '> broker:', bold=True), ws.broker.transport, ws.broker.hostname, ws.broker.port, ws.broker.virtual_host)) click.echo('{:23} {}'.format( _style(show_colors, '> queues:', bold=True), ', '.join([q.name for q in ws.queues]))) if details: click.echo('{:23} {}'.format( _style(show_colors, '> job count:', bold=True), ws.job_count)) jobs = list_jobs(config=obj['config'], filter_by_worker=ws.name) click.echo('{:23} [{}]'.format( _style(show_colors, '> jobs:', bold=True), len(jobs) if len(jobs) > 0 else 'No tasks')) for job in jobs: click.echo('{:15} {} {}'.format( '', _style(show_colors, '{}'.format(job.name), bold=True, fg=JOB_COLOR[job.type]), _style(show_colors, '({}) [{}] <{}> on {}'.format( job.type, job.workflow_id, job.id, job.worker_pid), fg=JOB_COLOR[job.type]))) click.echo('\n')
def api_list_registered_workflows(): """ Endpoint for listing all registered workflows. The result is a list of dictionaries comprised of the workflow fields with workflow information. """ return ApiResponse({ 'workflows': [ job.to_dict() for job in list_jobs(current_app.config['LIGHTFLOW'], status=JobStatus.Registered, filter_by_type=JobType.Workflow) ] })
def api_list_workers(): """ Endpoint for listing all workers and, if requested, all running jobs. The result is a list of workers. The result can be limited to certain queues by using the 'queue' argument. This argument can be used multiple times, e.g. ?queue=dag&queue=task. If the 'detail' is set to '1', all jobs running on a particular worker are returned as well. """ queues = request.args.getlist('queue') if queues is not None and len(queues) == 0: queues = None details = request.args.get('details', None) if details is not None: if details not in ['0', '1']: raise ApiError(StatusCode.BadRequest, 'The details argument must be either 0 or 1.') else: details = bool(int(details)) else: details = False workers = [ worker.to_dict() for worker in list_workers(config=current_app.config['LIGHTFLOW'], filter_by_queues=queues) ] if details: for worker in workers: worker['jobs'] = [ job.to_dict() for job in list_jobs(current_app.config['LIGHTFLOW'], filter_by_worker=worker['name']) ] return ApiResponse({'workers': workers})
def api_list_active_workflows(): """ Endpoint for listing all active workflows together with their dags and tasks. The result is a list of dictionaries comprised of the workflow fields with workflow information and lists of all the dags and tasks that are currently running. """ workflows = {} for job in list_jobs(current_app.config['LIGHTFLOW'], status=JobStatus.Active): if job.workflow_id not in workflows: workflows[job.workflow_id] = {'dags': [], 'tasks': []} if job.type == JobType.Dag: workflows[job.workflow_id]['dags'].append(job.to_dict()) elif job.type == JobType.Task: workflows[job.workflow_id]['tasks'].append(job.to_dict()) else: workflows[job.workflow_id] = { **workflows[job.workflow_id], **job.to_dict() } return ApiResponse({'workflows': list(workflows.values())})