Class: Specwrk::Web::Endpoints::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/specwrk/web/endpoints/base.rb

Direct Known Subclasses

Health, Heartbeat, Popable, Report, Seed, Shutdown

Constant Summary collapse

MUTEX =
Mutex.new
InvalidGzipError =
Class.new(StandardError)
UnsupportedContentEncodingError =
Class.new(StandardError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ Base

Returns a new instance of Base.



18
19
20
# File 'lib/specwrk/web/endpoints/base.rb', line 18

def initialize(request)
  @request = request
end

Instance Attribute Details

#started_atObject (readonly)

Returns the value of attribute started_at.



16
17
18
# File 'lib/specwrk/web/endpoints/base.rb', line 16

def started_at
  @started_at
end

Instance Method Details

#responseObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/specwrk/web/endpoints/base.rb', line 22

def response
  return with_response unless run_id # No run_id, no datastore usage in the endpoint

  payload # parse the payload before any locking

  worker.first_seen_at ||= Time.now
  worker.last_seen_at = Time.now

  started_at = [:started_at] ||= Time.now.iso8601
  @started_at = Time.parse(started_at)

  with_response.tap do |response|
    response[1]["x-specwrk-status"] = worker_status.to_s
  end
rescue Store::LockUnavailableError
  locked
rescue InvalidGzipError
  [400, {"content-type" => "text/plain"}, ["Invalid gzip request body"]]
rescue UnsupportedContentEncodingError
  [415, {"content-type" => "text/plain"}, ["Unsupported content encoding"]]
end

#with_responseObject



44
45
46
# File 'lib/specwrk/web/endpoints/base.rb', line 44

def with_response
  not_found
end