Sensor only dispatching triggers in debugging mode(while running sensor container log)

Below is the sample sensor written by me. It will poll a folder for new files in it and will dispatch a trigger as soon as it receives a new file. The sensor works fine when running the sensor container logs but does not work if i close the sensor container log.

import os
import json

from st2reactor.sensor.base import PollingSensor

class NewFileSensor(PollingSensor):

    def __init__(self, sensor_service, config=None, poll_interval=10):
            super(NewFileSensor, self).__init__(sensor_service=sensor_service, config=config, poll_interval=poll_interval)


            self._trigger_name = 'file_tracker'
            self._trigger_pack = 'jira'
            self._trigger_ref = '.'.join([self._trigger_pack, self._trigger_name])
            self._logger = self._sensor_service.get_logger(__name__)


    def setup(self):

            #self._directory_path = '/root/mimic_inbox/'
            self._all_files = os.listdir('/root/mimic_inbox/')


    def poll(self):
            self._detect_new_files()


    def cleanup(self):
            pass

    def add_trigger(self, trigger):
            pass

    def update_trigger(self, trigger):
            pass

    def remove_trigger(self, trigger):
            pass

    def _detect_new_files(self):
            new_files = os.listdir('/root/mimic_inbox/')

            for file in new_files:
                    if file not in self._all_files:
                            self._all_files.append(file)
                            self._dispatch_files_trigger(file)



    def _dispatch_files_trigger(self, file):
            trigger = self._trigger_ref
            file_path = '/root/mimic_inbox/' + file
            with open(file_path) as f:
                    data = json.load(f)

            payload = {
                    'from' : data['payload']['from'],
                    'to' : data['payload']['to'],
                    'body' : data['payload']['body'],
                    'subject' : data['payload']['subject'],
                    'date' : data['payload']['date']
            }
            self._sensor_service.dispatch(trigger, payload)

I need more information to help you more. Please keep in mind that 100% of the context I have into your problem is only what you write in your post.

  • How are you running the sensor?
    • In a Docker container?
    • A kubernetes container?
    • Have you tried running the container in daemon/detached mode?
  • Have you tried running the sensor outside of a container context? You can use st2vagrant to run ST2 in a development environment and develop your pack in that VM.
  • What is in the sensor logs?
  • What do you mean by “does not work”?
    • Does it not run at all?
    • Does it monitor directories but not report any new files?
    • Does it report new files but the triggers aren’t making it into ST2?