1

I am trying to understand how airflow works, I have a problem i created a dag in the order to check if my flask api works correctly, if it is not the case it must send an email. Attached is the code

def check_api_prod(id):
    data = ""
   
    url_siv = "http://111.11.11.111:5315/api/v1/search/"+str(id)
    
    body = {
        
    }
    res = requests.get(url_siv, json=body).json()
    
    
    
    if str(res['TAG']['id'])==str(id):
        return True
    else:
        raise AirflowException('l API est injoignable')
        

########################################################
#######################################################

def send_mail(receiver,object,Message ):

    msg = MIMEText(Message)

    msg["Subject"] = str(object)

    msg['From'] = "mp.name@gmail.com"
    

    with smtplib.SMTP('mail.gmx.com', 25) as smtp:
        smtp.ehlo()
        smtp.starttls() 
        smtp.ehlo()

        smtp.login("mp.name@gmail.com", "PASS_wrds?")


        try:

            smtp.sendmail("mp.name@gmail.com",  receiver, msg.as_string())
            print("mail sended")
        except Exception as er:
            print("error", er)



def error_api_email_function(self):
    
    try:
        
    
        receiver=["ch.mp@gmail.com", "fm@dgmail.fr"]
        
                 
        object="nouvelle version du message"
        Message_Echech=f" NOUVELLE VERSION du message "     
        now = datetime.now()   
        dt_string = now.strftime("%d/%m/%Y %H:%M:%S")
        Message_Echech=Message_Echech+ " "+dt_string
        envoi_mail(receiver,object,Message_Echech)
        print("mail envoyé")
     
       
    except Exception as er:
        print("impossible d'envoyer le mail à cause", er)



#################################################################
with DAG('Check_api', description='api 2', start_date=dt.datetime(year=2023, month=5, day=1), catchup=False,schedule_interval=dt.timedelta(minutes=5)) as dag:
    verifier_api=PythonOperator(
        task_id='check_api',
        python_callable=check_api_prod ,
        op_args=[ "GGMT34O"],
        on_failure_callback= error_api_email_function
       

    )

the code works correctly, the problem is that I wanted to stop the dag. I paused it, but the job is still running and I'm still receiving emails. I changed the airflow executor and I even stopped the containers and cleaned the images

docker compose up --all

I removed the dage file,but as soon as I re-build and restart the docker the job starts again !! any idea please ? enter image description here

how stop a ghost job on airflow

ensberg
  • 47
  • 6
  • https://en.wikipedia.org/wiki/The_Sorcerer%27s_Apprentice_(2001_film) – alexis May 09 '23 at 15:35
  • @alexis Hello, I didn't understand your answer, is it a wikipedia article about a movie? ! – ensberg May 10 '23 at 06:37
  • It's not an answer, I can't help you with your question I'm afraid. Pour predicament just reminded me of the Sorcerer's Apprentice (started an automation that he could not stop). Good luck! – alexis May 10 '23 at 09:38

0 Answers0