phanikumv commented on code in PR #26475:
URL: https://github.com/apache/airflow/pull/26475#discussion_r976421781
##########
airflow/providers/dbt/cloud/operators/dbt.py:
##########
@@ -218,3 +218,55 @@ def execute(self, context: Context) -> None:
json.dump(response.json(), file)
else:
file.write(response.text)
+
+
+class DbtCloudListJobsOperator(BaseOperator):
+ """
+ List jobs in a dbt Cloud project.
+
+ .. seealso::
+ For more information on how to use this operator, take a look at the
guide:
+ :ref:`howto/operator:DbtCloudListJobsOperator`
+
+ Retrieves metadata for all jobs tied to a specified dbt Cloud account. If
a ``project_id`` is
+ supplied, only jobs pertaining to this project id will be retrieved.
+
+ :param account_id: Required. The ID of a dbt Cloud account.
Review Comment:
done
##########
airflow/providers/dbt/cloud/operators/dbt.py:
##########
@@ -218,3 +218,55 @@ def execute(self, context: Context) -> None:
json.dump(response.json(), file)
else:
file.write(response.text)
+
+
+class DbtCloudListJobsOperator(BaseOperator):
+ """
+ List jobs in a dbt Cloud project.
+
+ .. seealso::
+ For more information on how to use this operator, take a look at the
guide:
+ :ref:`howto/operator:DbtCloudListJobsOperator`
+
+ Retrieves metadata for all jobs tied to a specified dbt Cloud account. If
a ``project_id`` is
+ supplied, only jobs pertaining to this project id will be retrieved.
+
+ :param account_id: Required. The ID of a dbt Cloud account.
+ :param order_by: Optional. Field to order the result by. Use '-' to
indicate reverse order.
+ For example, to use reverse order by the run ID use ``order_by=-id``.
+ :param project_id: Optional. The ID of a dbt Cloud project.
+ """
+
+ template_fields = (
+ "account_id",
+ "project_id",
+ )
+
+ def __init__(
+ self,
+ *,
+ dbt_cloud_conn_id: str = DbtCloudHook.default_conn_name,
+ account_id: int,
Review Comment:
done
##########
airflow/providers/dbt/cloud/operators/dbt.py:
##########
@@ -218,3 +218,55 @@ def execute(self, context: Context) -> None:
json.dump(response.json(), file)
else:
file.write(response.text)
+
+
+class DbtCloudListJobsOperator(BaseOperator):
+ """
+ List jobs in a dbt Cloud project.
+
+ .. seealso::
+ For more information on how to use this operator, take a look at the
guide:
+ :ref:`howto/operator:DbtCloudListJobsOperator`
+
+ Retrieves metadata for all jobs tied to a specified dbt Cloud account. If
a ``project_id`` is
+ supplied, only jobs pertaining to this project id will be retrieved.
+
+ :param account_id: Required. The ID of a dbt Cloud account.
+ :param order_by: Optional. Field to order the result by. Use '-' to
indicate reverse order.
+ For example, to use reverse order by the run ID use ``order_by=-id``.
+ :param project_id: Optional. The ID of a dbt Cloud project.
+ """
+
+ template_fields = (
+ "account_id",
+ "project_id",
+ )
+
+ def __init__(
+ self,
+ *,
+ dbt_cloud_conn_id: str = DbtCloudHook.default_conn_name,
+ account_id: int,
+ project_id: int | None = None,
+ order_by: str | None = None,
+ **kwargs,
+ ) -> None:
+ super().__init__(**kwargs)
+ self.dbt_cloud_conn_id = dbt_cloud_conn_id
+ self.account_id = account_id
+ self.project_id = project_id
+ self.order_by = order_by
+ self.hook: DbtCloudHook
+
+ def execute(self, context: Context) -> None:
+ self.hook = DbtCloudHook(self.dbt_cloud_conn_id)
+ list_jobs_response = self.hook.list_jobs(
+ account_id=self.account_id, order_by=self.order_by,
project_id=self.project_id
+ )
+ self.log.info(
+ "Jobs in the specified dbt Cloud account %s and project %s are:",
Review Comment:
`account_id` can be retrieved through the decorator(from the connection
object) or passed in the DAG. When retrieved through the decorator,
self.account_id is not set, leading to the below log.
```
[2022-09-21, 11:14:05 UTC] {dbt.py:269} INFO - Jobs in the specified dbt
Cloud account None are:
[2022-09-21, 11:14:05 UTC] {dbt.py:280} INFO - 128688
[2022-09-21, 11:14:05 UTC] {dbt.py:280} INFO - 128786
```
Hence I made the log statement to `"Jobs in the specified dbt Cloud account
are:"`
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]