def delete(name, force): """Delete scheduled job""" if not force: to_delete = get_scheduled_jobs(name_pattern=name) if not to_delete: click.echo("no jobs found matching the given name pattern") return click.echo("the following jobs will be deleted:") _click_echo_jobs(to_delete) click.confirm("are you sure?", abort=True) delete_scheduled_job(name)
def execute(self, airflow_context=None, allow_resubmit=True, handle_sigterm=True): self.task_run.airflow_context = airflow_context task_run = self.task_run run = task_run.run run_config = run.run_config task = self.task # type: Task task_engine = task_run.task_engine if allow_resubmit and task_engine._should_wrap_with_submit_task( task_run): args = task_engine.dbnd_executable + [ "execute", "--dbnd-run", str(run.driver_dump), "task_execute", "--task-id", task_run.task.task_id, ] submit_task = self.task_run.task_engine.submit_to_engine_task( env=task.task_env, task_name=SystemTaskName.task_submit, args=args) submit_task.task_meta.add_child(task.task_id) if run_config.open_web_tracker_in_browser: webbrowser.open_new_tab(task_run.task_tracker_url) run.run_dynamic_task(submit_task) return with self.task_run_execution_context(handle_sigterm=handle_sigterm): if run.is_killed(): raise friendly_error.task_execution.databand_context_killed( "task.execute_start of %s" % task) try: self.task_env.prepare_env() if run_config.skip_completed_on_run and task._complete(): task_run.set_task_reused() return task_run.set_task_run_state(state=TaskRunState.RUNNING) if not self.task.ctrl.should_run(): self.task.ctrl.validator.find_and_raise_missing_inputs() if run_config.validate_task_inputs: self.ctrl.validator.validate_task_inputs() try: result = self.task._task_submit() self.ctrl.save_task_band() if run_config.validate_task_outputs: self.ctrl.validator.validate_task_is_complete() finally: self.task_run.finished_time = utcnow() task_run.set_task_run_state(TaskRunState.SUCCESS) run.cleanup_after_task_run(task) return result except DatabandSigTermError as ex: logger.error( "Sig TERM! Killing the task '%s' via task.on_kill()", task_run.task.task_id, ) run._internal_kill() error = TaskRunError.build_from_ex(ex, task_run) try: task.on_kill() except Exception: logger.exception( "Failed to kill task on user keyboard interrupt") task_run.set_task_run_state(TaskRunState.CANCELLED, error=error) raise except KeyboardInterrupt as ex: logger.error("User Interrupt! Killing the task %s", task_run.task.task_id) error = TaskRunError.build_from_ex(ex, task_run) try: if task._conf_confirm_on_kill_msg: from dbnd._vendor import click if click.confirm(task._conf_confirm_on_kill_msg, default=True): task.on_kill() else: logger.warning( "Task is not killed accordingly to user input!" ) else: task.on_kill() except Exception: logger.exception( "Failed to kill task on user keyboard interrupt") task_run.set_task_run_state(TaskRunState.CANCELLED, error=error) run._internal_kill() raise except SystemExit as ex: error = TaskRunError.build_from_ex(ex, task_run) task_run.set_task_run_state(TaskRunState.CANCELLED, error=error) raise friendly_error.task_execution.system_exit_at_task_run( task, ex) except Exception as ex: error = TaskRunError.build_from_ex(ex, task_run) task_run.set_task_run_state(TaskRunState.FAILED, error=error) show_error_once.set_shown(ex) raise finally: task_run.airflow_context = None