Class: Dynflow::Connectors::Database::PostgresListerner

Inherits:
Object
  • Object
show all
Defined in:
lib/dynflow/connectors/database.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(core, world_id, db) ⇒ PostgresListerner

Returns a new instance of PostgresListerner.



7
8
9
10
11
12
# File 'lib/dynflow/connectors/database.rb', line 7

def initialize(core, world_id, db)
  @core     = core
  @db       = db
  @world_id = world_id
  @started  = Concurrent::AtomicReference.new
end

Class Method Details

.notify_supported?(db) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/dynflow/connectors/database.rb', line 14

def self.notify_supported?(db)
  db.class.name == "Sequel::Postgres::Database"
end

Instance Method Details

#notify(world_id) ⇒ Object



35
36
37
# File 'lib/dynflow/connectors/database.rb', line 35

def notify(world_id)
  @db.notify("world:#{world_id}")
end

#startObject



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/dynflow/connectors/database.rb', line 22

def start
  @started.set true
  @thread = Thread.new do
    @db.listen("world:#{@world_id}", :loop => true) do
      if started?
        @core << :check_inbox
      else
        break # the listener is stopped: don't continue listening
      end
    end
  end
end

#started?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/dynflow/connectors/database.rb', line 18

def started?
  @started.get
end

#stopObject



39
40
41
42
# File 'lib/dynflow/connectors/database.rb', line 39

def stop
  @started.set false
  notify(@world_id)
end