2

I'm trying to write a custom sensor that inherits BaseSensorOperator and SSHOperator. in the sensor body I override poke and execute method.

  class mysensor (BaseSensorOperator,SSHOperator):
      template_fields = ("my_param")
      def __init__ (
          self,
          my_param = None,
          *args,
          **kawags):
      self.my_param = my_param
      super().__init__(
          command = "some bash command",
          ssh_conn_id = "some connection"
          *args,
          **kwargs)

def poke(self, context):
    ... (implemented poke)
def execute():
    ...(implemented execute)
          

1 Answer 1

2

Custom sensors are required to implement only the poke function. You should not override the execute function (unless you really know what you are doing). The execute function is implemented in BaseSensorOperator and that is what gives sensors their capabilities.

In your case you should not use SSHOperator, you should use SSHHook directly.

Your Sensor should look like:

from airflow.providers.ssh.hooks.ssh import SSHHook

class Mysensor(BaseSensorOperator):
    ...

    def poke(self,context):
      hook = SSHHook(...)
      # add your sensor logic here
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.