def start_compute_attributes(revision_ids=None, event_id=None): """Start a background task for computed attributes.""" background_task.create_task( name="compute_attributes", url=flask.url_for(compute_attributes.__name__), parameters={"revision_ids": revision_ids, "event_id": event_id}, method="POST", queued_callback=compute_attributes ) db.session.commit()
def start_update_audit_issues(audit_id, message): """Start a background task to update IssueTracker issues related to Audit.""" background_task.create_task( name='update_audit_issues', url=flask.url_for(update_audit_issues.__name__), parameters={ 'audit_id': audit_id, 'message': message, }, method=u'POST', queued_callback=update_audit_issues, ) db.session.commit()
def reindex_pairs_bg(pairs): """Reindex selected snapshots in background. Args: pairs: A list of parent-child pairs that uniquely represent snapshot object whose properties should be reindexed. """ background_task.create_task( name="reindex_pairs_bg", url=flask.url_for(run_reindex_pairs_bg.__name__), parameters={"pairs": pairs}, queued_callback=run_reindex_pairs_bg, ) db.session.commit()
def start_update_cad_related_objs(event_id, model_name, need_revisions=None): """Start a background task to update related objects of CAD.""" background_task.create_task( name="update_cad_related_objects", url=flask.url_for(update_cad_related_objects.__name__), parameters={ "event_id": event_id, "model_name": model_name, "modified_by_id": login.get_current_user_id(), "need_revisions": need_revisions, }, method="POST", queued_callback=update_cad_related_objects ) db.session.commit()
def run_background_import(ie_job_id): """Run import job in background task.""" background_task.create_task( name="import", url=flask.url_for(run_import_phases.__name__), parameters={ "ie_id": ie_job_id, "parent": { "type": "ImportExport", "id": ie_job_id, } }, queue="ggrcImport", queued_callback=run_import_phases, operation_type=all_models.ImportExport.IMPORT_JOB_TYPE.lower(), ) db.session.commit()
def run_background_import(ie_job_id): """Run import job in background task.""" background_task.create_task( name="import", url=flask.url_for(run_import_phases.__name__), parameters={ "ie_id": ie_job_id, "parent": { "type": "ImportExport", "id": ie_job_id, } }, queue="ggrcImport", queued_callback=run_import_phases, operation_type=all_models.ImportExport.IMPORT_JOB_TYPE.lower(), retry_options={"task_retry_limit": 0}, ) db.session.commit()
def start_update_children_issues(parent_type, parent_id, child_type): """Start a background task to send comments to IssueTracker issues related to Audit child items """ background_task.create_task( name="delete_children_issues", url=flask.url_for(run_children_issues_updater.__name__), queued_callback=run_children_issues_updater, parameters={ "parent": { "type": parent_type, "id": parent_id }, "child_type": child_type }, operation_type="delete_children_issues", ) db.session.commit()
def admin_onetime_back_sync(): """Back sync for IssuetrackerIssues""" bg_task = background_task.create_task( name="onetime_back_sync", url=flask.url_for(onetime_back_sync.__name__), queued_callback=onetime_back_sync, ) db.session.commit() return bg_task.task_scheduled_response()
def admin_full_reindex(): """Calls a webhook that reindexes all indexable objects """ task_queue = create_task(name="full_reindex", url=url_for(full_reindex.__name__), queued_callback=full_reindex) return task_queue.make_response( app.make_response(("scheduled %s" % task_queue.name, 200, [('Content-Type', 'text/html')])))
def admin_reindex(): """Calls a webhook that reindexes indexable objects """ if not permissions.is_allowed_read("/admin", None, 1): raise Forbidden() task_queue = create_task("reindex", url_for(reindex.__name__), reindex) return task_queue.make_response( app.make_response(("scheduled %s" % task_queue.name, 200, [('Content-Type', 'text/html')])))
def start_compute_attributes(revision_ids): """Start a background task for computed attributes.""" task = create_task( name="compute_attributes", url=url_for(compute_attributes.__name__), parameters={"revision_ids": revision_ids}, method=u"POST", queued_callback=compute_attributes ) task.start()
def run_background_export(ie_job_id, objects, exportable_objects): """Run export job in background task.""" background_task.create_task( name="export", url=flask.url_for(run_export.__name__), parameters={ "ie_id": ie_job_id, "objects": objects, "exportable_objects": exportable_objects, "parent": { "type": "ImportExport", "id": ie_job_id, } }, queue="ggrcImport", queued_callback=run_export, operation_type=all_models.ImportExport.EXPORT_JOB_TYPE.lower(), ) db.session.commit()
def admin_create_missing_revisions(): """Create revisions for new objects""" admins = getattr(settings, "BOOTSTRAP_ADMIN_USERS", []) if get_current_user().email not in admins: raise exceptions.Forbidden() task_queue = create_task("create_missing_revisions", url_for( create_missing_revisions.__name__), create_missing_revisions) return task_queue.make_response( app.make_response(("scheduled %s" % task_queue.name, 200, [('Content-Type', 'text/html')])))
def admin_find_empty_revisions(): """Process all revisions and find empty.""" bg_task = background_task.create_task( name="find_empty_revisions", url=flask.url_for(find_empty_revisions.__name__), queued_callback=find_empty_revisions, ) db.session.commit() return bg_task.make_response( app.make_response(("scheduled %s" % bg_task.name, 200, [('Content-Type', 'text/html')])))
def admin_propagate_acl(): """Propagates all ACL entries""" admins = getattr(settings, "BOOTSTRAP_ADMIN_USERS", []) if get_current_user().email not in admins: raise exceptions.Forbidden() task_queue = create_task("propagate_acl", url_for( propagate_acl.__name__), propagate_acl) return task_queue.make_response( app.make_response(("scheduled %s" % task_queue.name, 200, [('Content-Type', 'text/html')])))
def admin_refresh_revisions(): """Calls a webhook that refreshes revision content.""" admins = getattr(settings, "BOOTSTRAP_ADMIN_USERS", []) if get_current_user().email not in admins: raise Forbidden() task_queue = create_task("refresh_revisions", url_for( refresh_revisions.__name__), refresh_revisions) return task_queue.make_response( app.make_response(("scheduled %s" % task_queue.name, 200, [('Content-Type', 'text/html')])))
def admin_reindex_snapshots(): """Calls a webhook that reindexes indexable objects """ task_queue = create_task( name="reindex_snapshots", url=url_for(reindex_snapshots.__name__), queued_callback=reindex_snapshots, ) return task_queue.make_response( app.make_response(("scheduled %s" % task_queue.name, 200, [('Content-Type', 'text/html')])))
def generate_wf_tasks_notifs(): """Generate notifications for updated wf cycle tasks.""" bg_task = background_task.create_task( name="generate_wf_tasks_notifications", url=flask.url_for(generate_wf_tasks_notifications.__name__), queued_callback=generate_wf_tasks_notifications, ) db.session.commit() return bg_task.make_response( app.make_response(("scheduled %s" % bg_task.name, 200, [('Content-Type', 'text/html')])))
def admin_propagate_acl(): """Propagates all ACL entries""" admins = getattr(settings, "BOOTSTRAP_ADMIN_USERS", []) if get_current_user().email not in admins: raise exceptions.Forbidden() task_queue = create_task("propagate_acl", url_for(propagate_acl.__name__), propagate_acl) return task_queue.make_response( app.make_response(("scheduled %s" % task_queue.name, 200, [('Content-Type', 'text/html')])))
def start_update_audit_issues(audit_id, message): """Start a background task to update IssueTracker issues related to Audit.""" task = create_task(name='update_audit_issues', url=url_for(update_audit_issues.__name__), parameters={ 'audit_id': audit_id, 'message': message, }, method=u'POST', queued_callback=update_audit_issues) task.start()
def admin_full_reindex(): """Calls a webhook that reindexes all indexable objects """ bg_task = background_task.create_task(name="full_reindex", url=flask.url_for( full_reindex.__name__), queued_callback=full_reindex) db.session.commit() return bg_task.make_response( app.make_response(("scheduled %s" % bg_task.name, 200, [('Content-Type', 'text/html')])))
def admin_full_reindex(): """Calls a webhook that reindexes all indexable objects """ task_queue = create_task( name="full_reindex", url=url_for(full_reindex.__name__), queued_callback=full_reindex ) return task_queue.make_response( app.make_response(("scheduled %s" % task_queue.name, 200, [('Content-Type', 'text/html')])))
def admin_full_reindex(): """Calls a webhook that reindexes all indexable objects """ bg_task = background_task.create_task( name="full_reindex", url=flask.url_for(full_reindex.__name__), queued_callback=full_reindex ) db.session.commit() return bg_task.make_response( app.make_response(("scheduled %s" % bg_task.name, 200, [('Content-Type', 'text/html')])))
def admin_create_missing_revisions(): """Create revisions for new objects""" admins = getattr(settings, "BOOTSTRAP_ADMIN_USERS", []) if get_current_user().email not in admins: raise exceptions.Forbidden() task_queue = create_task("create_missing_revisions", url_for(create_missing_revisions.__name__), create_missing_revisions) return task_queue.make_response( app.make_response(("scheduled %s" % task_queue.name, 200, [('Content-Type', 'text/html')])))
def run_bulk_verify(): """Call bulk verify job""" data = flask.request.json parameters = {"data": data} bg_task = background_task.create_task(name="bulk_verify", url=flask.url_for( bulk_verify.__name__), queued_callback=bulk_verify, parameters=parameters) db.session.commit() return bg_task.make_response( app.make_response( (utils.as_json(bg_task), 200, [('Content-Type', "text/json")])))
def update_issues(): """Bulk update linked issuetracker issues for provided objects. This endpoint update issuetracker tickets for all provided objects to the current state in the app. """ validate_bulk_sync_data(request.json) task_queue = create_task( "update_issues", url_for(run_issues_update.__name__), run_issues_update, request.json, ) return task_queue.task_scheduled_response()
def generate_issues(): """Bulk generate linked issuetracker issues for provided objects. This endpoint creates issuetracker tickets for all provided objects (if such tickets haven't been created before). """ validate_bulk_sync_data(request.json) task_queue = create_task( "generate_issues", url_for(run_issues_generation.__name__), run_issues_generation, request.json, ) return task_queue.task_scheduled_response()
def admin_propagate_acl(): """Propagates all ACL entries""" admins = getattr(settings, "BOOTSTRAP_ADMIN_USERS", []) if login.get_current_user().email not in admins: raise exceptions.Forbidden() bg_task = background_task.create_task( name="propagate_acl", url=flask.url_for(propagate_acl.__name__), queued_callback=propagate_acl, ) db.session.commit() return bg_task.make_response( app.make_response(("scheduled %s" % bg_task.name, 200, [('Content-Type', 'text/html')])))
def generate_issues(): """Bulk generate linked issuetracker issues for provided objects. This endpoint creates issuetracker tickets for all provided objects (if such tickets haven't been created before). """ validate_bulk_sync_data(flask.request.json) bg_task = background_task.create_task( name="generate_issues", url=flask.url_for(run_issues_generation.__name__), queued_callback=run_issues_generation, parameters=flask.request.json, ) db.session.commit() return bg_task.task_scheduled_response()
def admin_create_missing_revisions(): """Create revisions for new objects""" admins = getattr(settings, "BOOTSTRAP_ADMIN_USERS", []) if login.get_current_user().email not in admins: raise exceptions.Forbidden() bg_task = background_task.create_task( name="create_missing_revisions", url=flask.url_for(create_missing_revisions.__name__), queued_callback=create_missing_revisions, ) db.session.commit() return bg_task.make_response( app.make_response(("scheduled %s" % bg_task.name, 200, [('Content-Type', 'text/html')])))
def update_issues(): """Bulk update linked issuetracker issues for provided objects. This endpoint update issuetracker tickets for all provided objects to the current state in the app. """ validate_bulk_sync_data(flask.request.json) bg_task = background_task.create_task( name="update_issues", url=flask.url_for(run_issues_update.__name__), queued_callback=run_issues_update, parameters=flask.request.json, ) db.session.commit() return bg_task.task_scheduled_response()
def generate_children_issues(): """Generate linked issuetracker issues for children objects. This endpoint is used to create tickets for all specific type instances in scope of parent. For example it allows to create tickets for all Assessments in some Audit. """ validate_child_bulk_gen_data(request.json) task_queue = create_task( "generate_children_issues", url_for(run_children_issues_generation.__name__), run_children_issues_generation, request.json, operation_type="generate_children_issues", ) return task_queue.task_scheduled_response()
def background_update_issues(parameters=None): """Bulk update linked issuetracker issues for provided objects. This function update issuetracker tickets for all provided objects to the current state in the app. Can be called inside import task. """ method = "POST" bg_task = background_task.create_task( name="update_issues", url="/_background_tasks/background_issues_update", queued_callback=background_issues_update, parameters=parameters, method=method, ) db.session.commit() return bg_task.task_scheduled_response()
def generate_children_issues(): """Generate linked issuetracker issues for children objects. This endpoint is used to create tickets for all specific type instances in scope of parent. For example it allows to create tickets for all Assessments in some Audit. """ validate_child_bulk_gen_data(flask.request.json) bg_task = background_task.create_task( name="generate_children_issues", url=flask.url_for(run_children_issues_generation.__name__), queued_callback=run_children_issues_generation, parameters=flask.request.json, operation_type="generate_children_issues", ) db.session.commit() return bg_task.task_scheduled_response()
def create_indexing_bg_task(response): """Create background task for indexing Adds header 'X-GGRC-Indexing-Task-Id' with BG task id """ if hasattr(db.session, "reindex_set"): model_ids = db.session.reindex_set.model_ids_to_reindex if model_ids: with benchmark("Create indexing bg task"): chunk_size = db.session.reindex_set.CHUNK_SIZE bg_task = background_task.create_task( name="indexing", url=url_for(bg_update_ft_records.__name__), parameters={"models_ids": model_ids, "chunk_size": chunk_size}, queued_callback=bg_update_ft_records ) db.session.expunge_all() # improves plain_commit time db.session.add(bg_task) db.session.plain_commit() response.headers.add("X-GGRC-Indexing-Task-Id", bg_task.id) return response
def run_bulk_complete(): """Call bulk complete job""" data = flask.request.json parameters = {"data": data} if _detect_files(data): try: gdrive.get_http_auth() except gdrive.GdriveUnauthorized: response = app.make_response( ("auth", 401, [("Content-Type", "text/html")])) return response parameters["credentials"] = flask.session.get('credentials') bg_task = background_task.create_task(name="bulk_complete", url=flask.url_for( bulk_complete.__name__), queued_callback=bulk_complete, parameters=parameters) db.session.commit() return bg_task.make_response( app.make_response( (utils.as_json(bg_task), 200, [('Content-Type', "text/json")])))