This site is in read only mode. Please continue to browse, but replying, likes, and other actions are disabled for now.

⚠️ We've moved!

Hi there!

To reduce project dependency on 3rd party paid services the StackStorm TSC has decided to move the Q/A from this forum to Github Discussions. This will make user experience better integrated with the native Github flow, as well as the questions closer to the community where they can provide answers.

Use 🔗 Github Discussions to ask your questions.

Error while creating a poll sensor

I was trying to create a poll sensor to monitor a process on my sandbox, but failed with an error, which indicate my sensor initialization failed because of property of poll_interval.

init() got an unexpected keyword argument ‘poll_interval’

Has anybody encountered this problem before? I set the interval in the sensor yaml file to 10 seconds but the python code seems not recognizing this property.

Thank you

Can you post your code and metadata?

---
class_name: "BuildSchedulerSensor"
entry_point: "build_scheduler_sensor.py"
description: "Test if the build scheduler process is still running"
trigger_types:
  -
    name: "BuildSchedulerTrigger"
    description: "A BuildSchedulerSensor trigger."
    payload_schema:
      type: "object"
import eventlet

from st2reactor.sensor.base import Sensor


class BuildSchedulerSensor(Sensor):
    def __init__(self, sensor_service, config):
        super(BuildSchedulerSensor, self).__init__(sensor_service=sensor_service, config=config)
        self._logger = self.sensor_service.get_logger(name=self.__class__.__name__)
        self._stop = False

    def setup(self):
        pass

    def run(self):
        while not self._stop:
            self._logger.debug('BuildSchedulerSensor dispatching trigger...')
            count = self.sensor_service.get_value('tt_devops_engine.count') or 0
            payload = {'greeting': 'Yo, StackStorm!', 'count': int(count) + 1}
            self.sensor_service.dispatch(trigger='tt_devops_engine.event1', payload=payload)
            self.sensor_service.set_value('tt_devops_engine.count', payload['count'])
            eventlet.sleep(60)

    def cleanup(self):
        self._stop = True

    # Methods required for programmable sensors.
    def add_trigger(self, trigger):
        pass

    def update_trigger(self, trigger):
        pass

    def remove_trigger(self, trigger):
        pass

Actually, I am just using the sample sensor, but failed to start

Your code does not look like a PollingSensor. Look for “SamplePollingSensor” on this page Sensors and Triggers — StackStorm 2.10.1 documentation - note it inherits from PollingSensor, not Sensor

Thank you, I got this problem fixed by using polling sensor. :slight_smile:

1 Like