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 2022/11/24 18:25:26 UTC

[GitHub] [airflow] syedahsn commented on a diff in pull request #27893: AWSGlueJobHook updates job configuration if it exists

syedahsn commented on code in PR #27893:
URL: https://github.com/apache/airflow/pull/27893#discussion_r1031764389


##########
airflow/providers/amazon/aws/hooks/glue.py:
##########
@@ -92,10 +93,51 @@ def __init__(
         kwargs["client_type"] = "glue"
         super().__init__(*args, **kwargs)
 
+    def create_glue_job_config(self) -> dict:
+        if self.s3_bucket is None:
+            raise AirflowException("Could not initialize glue job, error: Specify Parameter `s3_bucket`")
+
+        default_command = {
+            "Name": "glueetl",
+            "ScriptLocation": self.script_location,
+        }
+        command = self.create_job_kwargs.pop("Command", default_command)
+
+        s3_log_path = f"s3://{self.s3_bucket}/{self.s3_glue_logs}{self.job_name}"
+        execution_role = self.get_iam_execution_role()
+
+        if "WorkerType" in self.create_job_kwargs and "NumberOfWorkers" in self.create_job_kwargs:
+            return dict(

Review Comment:
   This part here can be refactored to be a bit more concise. Rather than have two return statements returning very similar dictionaries, something like this would be cleaner:
   ```
   ret_config = {
       "Name": self.job_name,
       "Description": self.desc,
       "LogUri": s3_log_path,
       "Role": execution_role["Role"]["Arn"],
       "ExecutionProperty": {"MaxConcurrentRuns": self.concurrent_run_limit},
       "Command": command,
       "MaxRetries": self.retry_limit,
       **self.create_job_kwargs,
   }
   
   if "WorkerType" in self.create_job_kwargs and "NumberOfWorkers" in self.create_job_kwargs:
       ret_config["MaxCapacity"] = self.num_of_dpus
   
   return ret_config
   ```
   
   Also, it's [generally preferable](https://stackoverflow.com/questions/2853683/what-is-the-preferred-syntax-for-initializing-a-dict-curly-brace-literals-or/2853738#2853738) to use {} rather than the `dict()` function



-- 
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