Class: ExternalServicesRedis::Status

Inherits:
Common::RedisStore show all
Includes:
Common::CacheAside
Defined in:
app/models/external_services_redis/status.rb

Overview

Facade for the PagerDuty::ExternalServices::Service class.

Constant Summary collapse

KEY =
'pager_duty_services'

Constants inherited from Common::RedisStore

Common::RedisStore::REQ_CLASS_INSTANCE_VARS

Instance Method Summary collapse

Methods included from Common::CacheAside

#cache, #cached?, #do_cached_with

Methods inherited from Common::RedisStore

create, delete, #destroy, #destroyed?, exists?, #expire, find, find_or_build, #initialize, #initialize_dup, keys, #persisted?, pop, redis_key, redis_store, redis_ttl, #save, #save!, #ttl, #update, #update!

Constructor Details

This class inherits a constructor from Common::RedisStore

Instance Method Details

#fetch_or_cachePagerDuty::ExternalServices::Response

Returns either the cached response from the PagerDuty::ExternalServices::Service.new.get_services call, or makes a fresh call to that endpoint, then caches and returns the response.

Examples:

ExternalServicesRedis.new.fetch_or_cache.as_json

{
  "status"      => 200,
  "reported_at" => "2019-03-14T19:47:47.000Z",
  "statuses"    => [
    {
      "service"                 => "Appeals",
      "service_id"              => "appeals"
      "status"                  => "active",
      "last_incident_timestamp" => "2019-03-01T02:55:55.000-05:00"
    },
    ...
  ]
}

Returns:



45
46
47
# File 'app/models/external_services_redis/status.rb', line 45

def fetch_or_cache
  @response ||= response_from_redis_or_service
end

#reported_atTime

The time from the call to PagerDuty’s API

Returns:

  • (Time)

    For example, 2019-03-14 20:19:43 UTC



22
# File 'app/models/external_services_redis/status.rb', line 22

delegate :reported_at, to: :fetch_or_cache

#response_statusInteger

The HTTP status code from call to PagerDuty’s API

Returns:

  • (Integer)

    For example, 200



53
54
55
# File 'app/models/external_services_redis/status.rb', line 53

def response_status
  fetch_or_cache.status
end