alephant-broker 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/alephant-broker.gemspec +1 -0
- data/lib/alephant/broker/cache.rb +58 -0
- data/lib/alephant/broker/component.rb +12 -3
- data/lib/alephant/broker/version.rb +1 -1
- metadata +16 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce3d6afda8699e8e18f0988692abcd9abdc23bd5
|
4
|
+
data.tar.gz: 83fd6ac78a25d9d412ada73b072c48216a0a6793
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8314f42ed32e235903b076ddbb0649945114e406ffb548a990aab0e47ef7ee00907c79043d5d01fd5c7fc5543371d471ed09f169f8d096fbf454e268c9708c21
|
7
|
+
data.tar.gz: 2d9a27867bf43318d8bc1c5490bf0e4f8c7952ec3687c8939bf148788d00888c2a5806fdf663dc5c29b9c629ee836a71c8b60031ebee60f3784bbf7b98f55e00
|
data/alephant-broker.gemspec
CHANGED
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'dalli-elasticache'
|
2
|
+
require 'alephant/logger'
|
3
|
+
|
4
|
+
module Alephant
|
5
|
+
module Broker
|
6
|
+
module Cache
|
7
|
+
|
8
|
+
class Client
|
9
|
+
include Logger
|
10
|
+
|
11
|
+
DEFAULT_TTL = 2592000
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
unless config_endpoint.nil?
|
15
|
+
@@elasticache ||= ::Dalli::ElastiCache.new(config_endpoint, { :expires_in => ttl })
|
16
|
+
@client = @@elasticache.client
|
17
|
+
else
|
18
|
+
logger.info('Broker::Cache::Client#initialize: No config endpoint, NullClient used')
|
19
|
+
@client = NullClient.new
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def config_endpoint
|
24
|
+
Broker.config['elasticache_config_endpoint']
|
25
|
+
end
|
26
|
+
|
27
|
+
def ttl
|
28
|
+
Broker.config['elasticache_ttl'] || DEFAULT_TTL
|
29
|
+
end
|
30
|
+
|
31
|
+
def get(key, &block)
|
32
|
+
begin
|
33
|
+
result = @client.get(key)
|
34
|
+
logger.info("Broker::Cache::Client#get key: #{key} - #{result ? 'hit' : 'miss'}")
|
35
|
+
result ? result : set(key, block.call)
|
36
|
+
rescue StandardError => e
|
37
|
+
block.call if block_given?
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def set(key, value)
|
42
|
+
value.tap { |o| @client.set(key, o) }
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
class NullClient
|
48
|
+
def get(key); end
|
49
|
+
|
50
|
+
def set(key, value)
|
51
|
+
value
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
@@ -4,9 +4,11 @@ require 'alephant/cache'
|
|
4
4
|
require 'alephant/lookup'
|
5
5
|
require 'alephant/broker/errors/invalid_cache_key'
|
6
6
|
require 'alephant/sequencer'
|
7
|
+
require 'alephant/broker/cache'
|
7
8
|
|
8
9
|
module Alephant
|
9
10
|
module Broker
|
11
|
+
|
10
12
|
class Component
|
11
13
|
include Logger
|
12
14
|
|
@@ -15,11 +17,14 @@ module Alephant
|
|
15
17
|
def initialize(id, batch_id, options)
|
16
18
|
@id = id
|
17
19
|
@batch_id = batch_id
|
20
|
+
@cache = Cache::Client.new
|
18
21
|
@options = symbolize(options || {})
|
19
22
|
end
|
20
23
|
|
21
24
|
def load
|
22
|
-
@content ||= cache.get(
|
25
|
+
@content ||= @cache.get(cache_key) do
|
26
|
+
s3.get(s3_path)
|
27
|
+
end
|
23
28
|
end
|
24
29
|
|
25
30
|
def opts_hash
|
@@ -32,12 +37,16 @@ module Alephant
|
|
32
37
|
|
33
38
|
private
|
34
39
|
|
40
|
+
def cache_key
|
41
|
+
@cache_key ||= "#{id}/#{opts_hash}/#{version}"
|
42
|
+
end
|
43
|
+
|
35
44
|
def symbolize(hash)
|
36
45
|
Hash[hash.map { |k,v| [k.to_sym, v] }]
|
37
46
|
end
|
38
47
|
|
39
|
-
def
|
40
|
-
@
|
48
|
+
def s3
|
49
|
+
@s3_cache ||= Alephant::Cache.new(
|
41
50
|
Broker.config[:s3_bucket_id],
|
42
51
|
Broker.config[:s3_object_path]
|
43
52
|
)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alephant-broker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steven Jack
|
@@ -234,6 +234,20 @@ dependencies:
|
|
234
234
|
version: '0'
|
235
235
|
prerelease: false
|
236
236
|
type: :runtime
|
237
|
+
- !ruby/object:Gem::Dependency
|
238
|
+
name: dalli-elasticache
|
239
|
+
version_requirements: !ruby/object:Gem::Requirement
|
240
|
+
requirements:
|
241
|
+
- - '>='
|
242
|
+
- !ruby/object:Gem::Version
|
243
|
+
version: '0'
|
244
|
+
requirement: !ruby/object:Gem::Requirement
|
245
|
+
requirements:
|
246
|
+
- - '>='
|
247
|
+
- !ruby/object:Gem::Version
|
248
|
+
version: '0'
|
249
|
+
prerelease: false
|
250
|
+
type: :runtime
|
237
251
|
description: Brokers requests for alephant components
|
238
252
|
email:
|
239
253
|
- stevenmajack@gmail.com
|
@@ -251,6 +265,7 @@ files:
|
|
251
265
|
- Rakefile
|
252
266
|
- alephant-broker.gemspec
|
253
267
|
- lib/alephant/broker.rb
|
268
|
+
- lib/alephant/broker/cache.rb
|
254
269
|
- lib/alephant/broker/component.rb
|
255
270
|
- lib/alephant/broker/environment.rb
|
256
271
|
- lib/alephant/broker/errors/invalid_asset_id.rb
|