pankajkoti commented on code in PR #39178:
URL: https://github.com/apache/airflow/pull/39178#discussion_r1576106861
##########
airflow/providers/databricks/operators/databricks.py:
##########
@@ -884,3 +884,148 @@ class
DatabricksRunNowDeferrableOperator(DatabricksRunNowOperator):
def __init__(self, *args, **kwargs):
super().__init__(deferrable=True, *args, **kwargs)
+
+
+class DatabricksNotebookOperator(BaseOperator):
+ """
+ Runs a notebook on Databricks using an Airflow operator.
+
+ The DatabricksNotebookOperator allows users to launch and monitor notebook
+ job runs on Databricks as Airflow tasks.
+
+ .. seealso::
+ For more information on how to use this operator, take a look at the
guide:
+ :ref:`howto/operator:DatabricksNotebookOperator`
+
+ :param notebook_path: The path to the notebook in Databricks.
+ :param source: Optional location type of the notebook. When set to
WORKSPACE, the notebook will be retrieved
+ from the local Databricks workspace. When set to GIT, the notebook
will be retrieved from a Git repository
+ defined in git_source. If the value is empty, the task will use
GIT if git_source is defined
+ and WORKSPACE otherwise. For more information please visit
+
https://docs.databricks.com/dev-tools/api/latest/jobs.html#operation/JobsCreate
+ :param notebook_params: A dict of key-value pairs to be passed as optional
params to the notebook task.
+ :param notebook_packages: A list of the Python libraries to be installed
on the cluster running the
+ notebook.
+ :param new_cluster: Specs for a new cluster on which this task will be run.
+ :param existing_cluster_id: ID for existing cluster on which to run this
task.
+ :param job_cluster_key: The key for the job cluster.
+ :param databricks_conn_id: The name of the Airflow connection to use.
+ """
+
+ template_fields = ("notebook_params",)
+
+ def __init__(
+ self,
+ notebook_path: str,
+ source: str,
+ notebook_params: dict | None = None,
+ notebook_packages: list[dict[str, Any]] | None = None,
+ new_cluster: dict[str, Any] | None = None,
+ existing_cluster_id: str | None = None,
+ job_cluster_key: str | None = None,
+ polling_period_seconds: int = 5,
+ databricks_retry_limit: int = 3,
+ databricks_retry_delay: int = 1,
+ databricks_retry_args: dict[Any, Any] | None = None,
+ databricks_conn_id: str = "databricks_default",
+ **kwargs: Any,
+ ):
+ self.notebook_path = notebook_path
+ self.source = source
+ self.notebook_params = notebook_params or {}
+ self.notebook_packages = notebook_packages or []
+ self.new_cluster = new_cluster or {}
+ self.existing_cluster_id = existing_cluster_id or ""
+ self.job_cluster_key = job_cluster_key or ""
+ self.polling_period_seconds = polling_period_seconds
+ self.databricks_retry_limit = databricks_retry_limit
+ self.databricks_retry_delay = databricks_retry_delay
+ self.databricks_retry_args = databricks_retry_args
+ self.databricks_conn_id = databricks_conn_id
+ self.databricks_run_id = ""
+ super().__init__(**kwargs)
+
+ @cached_property
+ def _hook(self):
+ return self._get_hook(caller="DatabricksNotebookOperator")
+
+ def _get_hook(self, caller: str) -> DatabricksHook:
+ return DatabricksHook(
+ self.databricks_conn_id,
+ retry_limit=self.databricks_retry_limit,
+ retry_delay=self.databricks_retry_delay,
+ retry_args=self.databricks_retry_args,
+ caller=caller,
+ )
+
+ def _get_task_base_json(self) -> dict[str, Any]:
+ """Get task base json to be used for task submissions."""
+ return {
+ # Timeout seconds value of 0 for the Databricks Jobs API means the
job runs forever.
+ # That is also the default behavior of Databricks jobs to run a
job forever without a default
+ # timeout value.
+ "timeout_seconds": int(self.execution_timeout.total_seconds()) if
self.execution_timeout else 0,
Review Comment:
moved to a separate method.
From a Databricks perspective, the default timeout is 0 as well. Linked the
docs in the docstring for the method as you suggested earlier.
--
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]