Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id C55D5200BA6 for ; Tue, 18 Oct 2016 22:13:37 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id C3ECE160AE5; Tue, 18 Oct 2016 20:13:37 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id DFA02160ACE for ; Tue, 18 Oct 2016 22:13:36 +0200 (CEST) Received: (qmail 23507 invoked by uid 500); 18 Oct 2016 20:13:36 -0000 Mailing-List: contact dev-help@airflow.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@airflow.incubator.apache.org Delivered-To: mailing list dev@airflow.incubator.apache.org Received: (qmail 23495 invoked by uid 99); 18 Oct 2016 20:13:35 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 18 Oct 2016 20:13:35 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 46EC6C0B9C for ; Tue, 18 Oct 2016 20:13:35 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 3.15 X-Spam-Level: *** X-Spam-Status: No, score=3.15 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=2, KAM_INFOUSMEBIZ=0.75, RCVD_IN_SORBS_SPAM=0.5] autolearn=disabled Authentication-Results: spamd1-us-west.apache.org (amavisd-new); dkim=pass (1024-bit key) header.d=boristyukin.com Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id G0AEBwNmFUJ0 for ; Tue, 18 Oct 2016 20:13:33 +0000 (UTC) Received: from s2.fcomet.com (s2.fcomet.com [99.198.101.250]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id 623995F1D5 for ; Tue, 18 Oct 2016 20:13:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=boristyukin.com; s=default; h=Content-Type:To:Subject:Message-ID:Date:From: References:In-Reply-To:MIME-Version:Sender:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=yxuumayaYflLjR2Ab2uk/KOyf9PrztZQ56fjSLaHkp8=; b=lm6yP57NBFHPS7/wUQ1Sk9I/m CQmdH1bR5z0p1/JZgVNeJdDxr9hIhOZsUViAvgA1uWC3kIcOfWJIDUn4H712FsB5gSFykmrHaKfHY 7b9iQVml93NTPdq15DSWEY3GZnvPywvNv0knc52XMcWLIYqPkg+sd3aBvMTmEMYR50P4Y=; Received: from mail-oi0-f47.google.com ([209.85.218.47]:34288) by s2.fcomet.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.87) (envelope-from ) id 1bwalO-003TQE-Dz for dev@airflow.incubator.apache.org; Tue, 18 Oct 2016 15:13:30 -0500 Received: by mail-oi0-f47.google.com with SMTP id t73so6256737oie.1 for ; Tue, 18 Oct 2016 13:13:30 -0700 (PDT) X-Gm-Message-State: AA6/9Rk5YWZrd01TibUYt3lHVrms8uHPxiNms+SceHTwhzjh+mGsRiUb0rWAgX1Z7pVPXm0xdLbRNFJpXFW34g== X-Received: by 10.157.31.18 with SMTP id x18mr1319574otd.29.1476821610057; Tue, 18 Oct 2016 13:13:30 -0700 (PDT) MIME-Version: 1.0 Received: by 10.202.8.78 with HTTP; Tue, 18 Oct 2016 13:12:59 -0700 (PDT) In-Reply-To: References: From: Boris Tyukin Date: Tue, 18 Oct 2016 16:12:59 -0400 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: Usage of "on_failure_callback" ? To: dev@airflow.incubator.apache.org Content-Type: multipart/alternative; boundary=001a113d028c76dda3053f295323 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - s2.fcomet.com X-AntiAbuse: Original Domain - airflow.incubator.apache.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - boristyukin.com X-Get-Message-Sender-Via: s2.fcomet.com: authenticated_id: boris@boristyukin.com X-Authenticated-Sender: s2.fcomet.com: boris@boristyukin.com archived-at: Tue, 18 Oct 2016 20:13:37 -0000 --001a113d028c76dda3053f295323 Content-Type: text/plain; charset=UTF-8 hi Jason, here is an example below - in task0_python_callable i did 1/0 to raise an error and Airflow then called task0_failure_cb. I could see FAIL in the task log so my task0_failure_cb was definitely invoked. The task would still have failed status if look at UI. Are you expecting a different behavior? def task0_python_callable(ds, **kwargs): print ds print 1/0 return 'Success!!! Execution time = {}'.format(kwargs['execution_date']) def task0_failure_cb(ds, **kwargs): logging.info("FAIL") task0 = PythonOperator( task_id='task0', python_callable=task0_python_callable, on_failure_callback=task0_failure_cb, provide_context=True, dag=dag) [2016-10-18 16:07:02,631] {models.py:154} INFO - Filling up the DagBag from /home/oracle/airflow/dags/fail_callback.py [2016-10-18 16:07:03,239] {models.py:154} INFO - Filling up the DagBag from /home/oracle/airflow/dags/fail_callback.py [2016-10-18 16:07:03,312] {models.py:1196} INFO - -------------------------------------------------------------------------------- Starting attempt 1 of 1 -------------------------------------------------------------------------------- [2016-10-18 16:07:03,317] {models.py:1219} INFO - Executing on 2016-10-18 16:06:02 [2016-10-18 16:07:03,322] {models.py:1286} ERROR - integer division or modulo by zero Traceback (most recent call last): File "/usr/local/lib/python2.7/site-packages/airflow/models.py", line 1245, in run result = task_copy.execute(context=context) File "/usr/local/lib/python2.7/site-packages/airflow/operators/python_operator.py", line 66, in execute return_value = self.python_callable(*self.op_args, **self.op_kwargs) File "/home/oracle/airflow/dags/fail_callback.py", line 33, in task0_python_callable print 1/0 ZeroDivisionError: integer division or modulo by zero [2016-10-18 16:07:03,324] {models.py:1306} INFO - Marking task as FAILED. [2016-10-18 16:07:03,324] {fail_callback.py:38} INFO - FAIL [2016-10-18 16:07:03,327] {models.py:1327} ERROR - integer division or modulo by zero On Tue, Oct 18, 2016 at 2:59 PM, Jason Chen wrote: > Hi airflow team, > > Is there any sample code to use "on_failure_callback" ? > I tried to use that as a callback to "post-process" when a task fails. > However, I cannot make it work. > > The definition of my task is as below (just one task in my dag). > > It invokes "task0_python_callable" which executes a command-line script and > it could drops exception. It in turns making task0 failed. > In that case, I am thinking it should trigger the "on_failure_callback" > function "task0_failure_cb", but it does not happen. > > Any suggestion? > Thanks. > > Jason > > ========= > task0 = PythonOperator( > task_id='task0', > python_callable=task0_python_callable, > on_failure_callback=task0_failure_cb, > dag=dag) > --001a113d028c76dda3053f295323--