You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2021/11/03 13:12:01 UTC

[GitHub] [airflow] mik-laj commented on a change in pull request #19377: Providers facebook hook multiple account

mik-laj commented on a change in pull request #19377:
URL: https://github.com/apache/airflow/pull/19377#discussion_r741921242



##########
File path: airflow/providers/facebook/ads/hooks/ads.py
##########
@@ -119,25 +120,30 @@ def bulk_facebook_report(
         :type sleep_time: int
 
         :return: Facebook Ads API response, converted to Facebook Ads Row objects
-        :rtype: List[AdsInsights]
+        :rtype: Dict[str, List[AdsInsights]]
         """
+        all_insights = {}
         api = self._get_service()
-        ad_account = AdAccount(api.get_default_account_id(), api=api)
-        _async = ad_account.get_insights(params=params, fields=fields, is_async=True)
-        while True:
-            request = _async.api_get()
-            async_status = request[AdReportRun.Field.async_status]
-            percent = request[AdReportRun.Field.async_percent_completion]
-            self.log.info("%s %s completed, async_status: %s", percent, "%", async_status)
-            if async_status == JobStatus.COMPLETED.value:
-                self.log.info("Job run completed")
-                break
-            if async_status in [JobStatus.SKIPPED.value, JobStatus.FAILED.value]:
-                message = f"{async_status}. Please retry."
-                raise AirflowException(message)
-            time.sleep(sleep_time)
-        report_run_id = _async.api_get()["report_run_id"]
-        report_object = AdReportRun(report_run_id, api=api)
-        insights = report_object.get_insights()
-        self.log.info("Extracting data from returned Facebook Ads Iterators")
-        return list(insights)
+        for account_id in self.facebook_ads_config["account_id"]:
+            ad_account = AdAccount(account_id, api=api)
+            _async = ad_account.get_insights(params=params, fields=fields, is_async=True)
+            while True:
+                request = _async.api_get()
+                async_status = request[AdReportRun.Field.async_status]
+                percent = request[AdReportRun.Field.async_percent_completion]
+                self.log.info("%s %s completed, async_status: %s", percent, "%", async_status)
+                if async_status == JobStatus.COMPLETED.value:
+                    self.log.info("Job run completed")
+                    break
+                if async_status in [JobStatus.SKIPPED.value, JobStatus.FAILED.value]:
+                    message = f"{async_status}. Please retry."
+                    raise AirflowException(message)
+                time.sleep(sleep_time)
+            report_run_id = _async.api_get()["report_run_id"]
+            report_object = AdReportRun(report_run_id, api=api)
+            self.log.info("Extracting data from returned Facebook Ads Iterators")
+            all_insights[account_id] = list(report_object.get_insights())
+            self.log.info(
+                str(account_id) + " Account Id used to extract data from Facebook Ads Iterators successfully"
+            )

Review comment:
       ```suggestion
               self.log.info(
                   "%s Account Id used to extract data from Facebook Ads Iterators successfully", account_id
               )
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org