def collector(project_name, network, collector_id, task_id=None): """ Loads the detail / control page for a collector """ # Redirects an admin back to the homepage b/c nothing is loaded into the session yet if g.project is None: flash( 'Please navigate to the New Collector page from your homepage panel.' ) return redirect(url_for('index')) form = ProcessControlForm(request.form) # Loads collector info for the page db = DB() resp = db.get_collector_detail(g.project['project_id'], collector_id) collector = resp['collector'] # Loads active status resp = db.check_process_status(g.project['project_id'], 'collect', collector_id=collector_id) active_status = resp['message'] # If a start/stop/restart is in progress, display the status task_status = None if task_id: resp = celery.AsyncResult(task_id) if resp.state == 'PENDING': task_status = 'Collector start/shutdown still in progress...' else: task_status = 'Collector start/shutdown completed.' return render_template('collector.html', collector=collector, active_status=active_status, form=form, task_status=task_status)
def network_home(project_name, network, task_id=None): """ Renders a project account's homepage """ # Loads project details if an admin if g.admin is not None: _aload_project(project_name) # Grabs collectors for the given network if not g.project['collectors']: collectors = None else: collectors = [ c for c in g.project['collectors'] if c['network'] == network ] for collector in collectors: collector['num_terms'] = 0 if collector['terms_list'] is not None: collector['num_terms'] = len(collector['terms_list']) g.project['num_collectors'] = len(collectors) processor_form = ProcessControlForm(request.form) inserter_form = ProcessControlForm(request.form) # Loads processor active status db = DB() resp = db.check_process_status(g.project['project_id'], 'process', module=network) processor_active_status = resp['message'] # Loads inserter active status resp = db.check_process_status(g.project['project_id'], 'insert', module=network) inserter_active_status = resp['message'] # Loads count of tweets in the storage DB count = db.get_storage_counts(g.project['project_id'], network) # If a start/stop/restart is in progress, display the status task_status = None if task_id: resp = celery.AsyncResult(task_id) if resp.state == 'PENDING': processor_task_status = 'Processor/Inserter start/shutdown still in progress...' else: processor_task_status = 'Processor/Inserter start/shutdown completed.' return render_template('network_home.html', network=network, collectors=collectors, project_detail=g.project, processor_active_status=processor_active_status, inserter_active_status=inserter_active_status, task_status=task_status, count=count, processor_form=processor_form, inserter_form=inserter_form)