title: Dynamically change the number of task retries
body: <p>Retrying a task may be pointless. For example, if the task is a sensor and it failed because it had invalid credentials then any future retries would inevitably fail. How can I define Operators that can decide if a retry is sensible?</p>
  
  <p>In Airflow 1.10.6, the logic that decides if a task should be retried or not is in <code>airflow.models.taskinstance.TaskInstance.handle_failure</code>, making it impossible to define the behavior in the operator as it is a responsibility of the task and not the operator.</p>
  
  <p>An ideal case would be if the <code>handle_failure</code> method was defined in the Operator's side so we can re-define it as needed.</p>
  
  <p>The only workaround I found was using <code>PythonBranchingOperator</code> to "test" if the task can be run or not. For example, in the case of the sensor above, checking if the login credentials are valid and only then take the DAG flow to the sensor. Otherwise, fail (or branch to another task).</p>
  
  <p>Is my analysis of <code>handle_failure</code> correct? Is there a better workaround?</p>