def _check_dv360_report(self, job_config: Dict[str, Any], run_config: Dict[str, Any]): """Check a running DV360 report for completion Arguments: report {Dict[str, Any]} -- The report data structure from Firestore """ job_attributes = job_config['pubsubTarget']['attributes'] dbm = DBM(email=job_attributes['email'], project=self.project) status = dbm.report_state(job_attributes['report_id']) append = job_attributes[ 'append'] if job_attributes and 'append' in job_attributes else False logging.info('Report {report} status: {status}'.format( report=job_attributes['report_id'], status=status)) if status == 'DONE': # Remove job from running self.firestore.remove_report_runner(job_attributes['report_id']) # Send pubsub to trigger report2bq now topic = job_config['pubsubTarget']['topicName'] self.PS.publish(topic=topic, data=b'RUN', **job_attributes) elif status == 'FAILED': # Remove job from running logging.error(f'Report {run_config["report_id"]} failed!') self.firestore.remove_report_runner(run_config['report_id'])
def _attended_run(self, dbm: DBM) -> None: """_attended_run. Run the report and wait for it to finish. Args: dbm (DBM): The DV360 controller. """ response = dbm.run_report(self.dbm_id) if response: buffer = StringIO() pprint.pprint(response, stream=buffer) logging.info(buffer.getvalue()) while True: status = dbm.report_state(self.dbm_id) logging.info(f'Report {self.dbm_id} status: {status}') if status == 'RUNNING': time.sleep(10) elif status == 'DONE': report2bq = Report2BQ(dv360=True, dv360_id=self.dbm_id, email=self.email, project=self.project) report2bq.handle_report_fetcher(fetcher=dbm, report_id=self.dbm_id) break else: logging.error( f'DV360 Report {self.dbm_id} failed to run: {status}') break
def _check_dv360_report(self, job_config: Dict[str, Any], run_config: Dict[str, Any]) -> None: """Check a running DV360 report for completion. Args: job_config (Dict[str, Any]): job configuration run_config (Dict[str, Any]): current run configuration """ job_attributes = job_config['pubsubTarget']['attributes'] dbm = DBM(email=job_attributes['email'], project=job_attributes['project']) status = dbm.report_state(run_config['report_id']) logging.info('Report %s status: %s', run_config['report_id'], status) if status == 'DONE': # Send pubsub to trigger report2bq now topic = f'projects/{self.project}/topics/report2bq-fetcher' self.pubsub_client.publish(topic=topic, data=b'RUN', **job_attributes) # Remove job from running self.remove_report_runner(run_config['report_id']) elif status == 'FAILED': # Remove job from running logging.error(f'Report %s failed!', run_config['report_id']) self.remove_report_runner(run_config['report_id']) else: self.update_report_runner(run_config['report_id'], status)
def run(self, unattended: bool = True): dbm = DBM(email=self.email, project=self.project) if unattended: self._unattended_run(dbm) else: self._attended_run(dbm)
def _unattended_run(self, dbm: DBM) -> None: response = dbm.run_report(self.dbm_id) if response: runner = { 'type': Type.DV360.value, 'project': self.project, 'report_id': self.dbm_id, 'email': self.email, } self.firestore.store_report_runner(runner)
def run(self, unattended: bool = True): """Perform the report run Args: unattended (bool, optional): Is this a fire and forget (True) or wait for the report to complete (False). Defaults to True. """ dbm = DBM(email=self.email, project=self.project) if unattended: self._unattended_run(dbm) else: self._attended_run(dbm)
def create_fetcher(product: Type, **kwargs) -> ReportFetcher: fetcher = None if product == Type.DV360: fetcher = DBM(**kwargs) elif product == Type.CM: fetcher = DCM(**kwargs) elif product == Type.SA360: fetcher = SA360(**kwargs) else: raise Exception(f'Cannot create fetcher for {product}') return fetcher
def _unattended_run(self, dbm: DBM) -> None: """_unattended_run. Start the report running and store the run configuration in Firestore. This will then be monitored for completion and import by the run-monitor. Args: dbm (DBM): The DV360 controller. """ response = dbm.run_report(self.dbm_id) if response: runner = { 'type': Type.DV360.value, 'project': self.project, 'report_id': self.dbm_id, 'email': self.email, } self.firestore.store_document(type=Type._RUNNING, id=runner['report_id'], document=runner)