Class: StraightServer::Thread

Inherits:
Object
  • Object
show all
Defined in:
lib/straight-server/thread.rb

Constant Summary collapse

INTERRUPTION_FLAG =
lambda { |label| "#{Config[:'redis.prefix']}:interrupt_thread:#{label}" }

Class Method Summary collapse

Class Method Details

.interrupt(label:) ⇒ Object



12
13
14
15
# File 'lib/straight-server/thread.rb', line 12

def self.interrupt(label:)
  redis = StraightServer.redis_connection
  redis.set INTERRUPTION_FLAG[label], Time.now.to_i
end

.interrupted?(thread:) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
# File 'lib/straight-server/thread.rb', line 17

def self.interrupted?(thread:)
  redis  = StraightServer.redis_connection
  result = redis.get(key = INTERRUPTION_FLAG[thread[:label]])
  redis.del key if result
  !!result
end

.new(label: nil, &block) ⇒ Object



4
5
6
7
8
# File 'lib/straight-server/thread.rb', line 4

def self.new(label: nil, &block)
  thread         = ::Thread.new(&block)
  thread[:label] = label
  thread
end