Skip to content

Managing listener lifecycle #570

Description

@christopher-b

Hi Folks, I have a class that includes a listener as a rails "class attribute":

module MyModule
  class MyClass
    cattr_accessor(:file_listener)

    def initialize
      initialize_file_listener
    end

    def initialize_file_listener
      self.file_listener&.stop

      self.file_listener = Listen.to(config[:local_path]) do |modified, added, _|
        # ...
      end

      self.file_listener.start
    end
  end
end

I periodically get this exception when calling start:

ArgumentError: Listen::Listener can't change state from 'stopped' to 'processing_events', only to: backend_started

I'm not sure why this is happening. I believe I'm setting the file_listener variable to a new Listener instance, so the state of that instance should be the default state, :initializing.

Unfortunately, there's nothing in my logs to shed light on this (I have set LISTEN_GEM_DEBUGGING=debug).

Is there additional lifecycle management I need to do on the listeners? Is there a better approach to be taking?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions