def insert_task_data(self): celery_id = "" if current_task._get_current_object(): celery_id = current_task.request.id task_data = { 'name': self.task_name, 'target': self.ip_target, 'start_time': '-', 'end_time': '-', 'status': TaskStatus.WAITING, 'type': 'ip', 'options': { "port_scan_type": "test", "port_scan": True, "service_detection": False, "os_detection": False, "site_identify": False, "site_capture": False, "file_leak": False, "site_spider": False, "ssl_cert": False, 'scope_id': self.scope_id }, 'celery_id': celery_id } if self.options is None: self.options = {} task_data["options"].update(self.options) conn('task').insert_one(task_data) self.task_id = str(task_data.pop("_id"))
def wrap_domain_executors(base_domain=None, job_id=None, scope_id=None, options=None, name=""): celery_id = "" if current_task._get_current_object(): celery_id = current_task.request.id task_data = { 'name': name, 'target': base_domain, 'start_time': '-', 'status': 'waiting', 'type': 'domain', 'task_tag': 'monitor', #标记为监控任务 'options': { 'domain_brute': True, 'domain_brute_type': 'test', 'riskiq_search': False, 'alt_dns': False, 'arl_search': True, 'port_scan_type': 'test', 'port_scan': True, 'service_detection': False, 'service_brute': False, 'os_detection': False, 'site_identify': False, 'site_capture': False, 'file_leak': False, 'site_spider': False, 'search_engines': False, 'ssl_cert': False, 'fofa_search': False, 'scope_id': scope_id }, 'celery_id': celery_id } if options is None: options = {} task_data["options"].update(options) conn('task').insert_one(task_data) task_id = str(task_data.pop("_id")) domain_executor = DomainExecutor(base_domain, task_id, task_data["options"]) try: update_job_run(job_id) new_domain = domain_executor.run() if new_domain: sync_asset(task_id, scope_id, update_flag=True) except Exception as e: logger.exception(e) domain_executor.update_task_field("status", TaskStatus.ERROR) domain_executor.update_task_field("end_time", utils.curr_date()) logger.info("end domain_executors {} {} {}".format(base_domain, scope_id, options))
def ctx_celery_task_get_request_id(): """ Fetch the request id from the headers of the current celery task. """ if current_task._get_current_object() is None: raise ExecutedOutsideContext() return current_task.request.get(_CELERY_X_HEADER, None)
def get_session() -> Session: """Get a database session. :returns: a database session :rtype: :class:`~.orm.Session` """ task = current_task._get_current_object() request = task.request if getattr(request, 'db_session', None) is None: request.db_session = Session(bind=get_database_engine()) return request.db_session
def celery_task_request_get(key): from celery import current_task if current_task._get_current_object() is not None: return current_task.request.get(key, None)
def _routing_key(self, task_id): task = current_task._get_current_object() if task is not None: return task.request.reply_to
def _is_in_context(): if current_task._get_current_object() is None: # pylint: disable=protected-access raise ExecutedOutsideContext()
def get_session() -> Session: task = current_task._get_current_object() request = task.request if getattr(request, 'db_session', None) is None: request.db_session = Session(bind=get_database_engine()) return request.db_session