nuclearpinguin commented on a change in pull request #7400: [AIRFLOW-6759] 
Added MLEngine operator/hook to cancel MLEngine jobs
URL: https://github.com/apache/airflow/pull/7400#discussion_r377744740
 
 

 ##########
 File path: airflow/providers/google/cloud/hooks/mlengine.py
 ##########
 @@ -148,6 +148,51 @@ def create_job(
 
         return self._wait_for_job_done(project_id, job_id)
 
+    @CloudBaseHook.fallback_to_default_project_id
+    def cancel_job(
+        self,
+        job_id,
+        project_id: Optional[str] = None
+    ) -> Dict:
+
+        """
+        Cancels a MLEngine job.
+
+        :param project_id: The Google Cloud project id within which MLEngine
+            job will be launched. If set to None or missing, the default 
project_id from the GCP
+            connection is used.
+        :type project_id: str
+        :param job_id: A unique id for the want-to-be cancelled Google 
MLEngine training job.
+        :type job_id: str
+
+        :return: Empty dict if cancelled successfully
+        :rtype: dict
+        :raises: googleapiclient.errors.HttpError
+        """
+
+        if not project_id:
+            raise ValueError("The project_id should be set")
+
+        hook = self.get_conn()
+
+        request = hook.projects().jobs().cancel(  # pylint: disable=no-member
+            name='projects/{}/jobs/{}'.format(project_id, job_id))
 
 Review comment:
   ```suggestion
               name=f'projects/{project_id}/jobs/{job_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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to