Source code for airflow.providers.amazon.aws.sensors.sagemaker_training
## Licensed to the Apache Software Foundation (ASF) under one# or more contributor license agreements. See the NOTICE file# distributed with this work for additional information# regarding copyright ownership. The ASF licenses this file# to you under the Apache License, Version 2.0 (the# "License"); you may not use this file except in compliance# with the License. You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing,# software distributed under the License is distributed on an# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY# KIND, either express or implied. See the License for the# specific language governing permissions and limitations# under the License.importtimefromtypingimportOptionalfromairflow.providers.amazon.aws.hooks.sagemakerimportLogState,SageMakerHookfromairflow.providers.amazon.aws.sensors.sagemaker_baseimportSageMakerBaseSensor
[docs]classSageMakerTrainingSensor(SageMakerBaseSensor):""" Asks for the state of the training state until it reaches a terminal state. If it fails the sensor errors, failing the task. :param job_name: name of the SageMaker training job to check the state of :type job_name: str :param print_log: if the operator should print the cloudwatch log :type print_log: bool """
[docs]definit_log_resource(self,hook:SageMakerHook)->None:"""Set tailing LogState for associated training job."""description=hook.describe_training_job(self.job_name)self.instance_count=description['ResourceConfig']['InstanceCount']status=description['TrainingJobStatus']job_already_completed=statusnotinself.non_terminal_states()self.state=LogState.TAILINGifnotjob_already_completedelseLogState.COMPLETEself.last_description=descriptionself.last_describe_job_call=time.monotonic()self.log_resource_inited=True