alephant 0.0.6-java → 0.0.7-java
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/README.md +5 -1
- data/alephant.gemspec +1 -1
- data/lib/alephant.rb +7 -1
- data/lib/alephant/models/cache.rb +4 -0
- data/lib/alephant/models/logger.rb +22 -0
- data/lib/alephant/models/queue.rb +6 -0
- data/lib/alephant/models/renderer.rb +13 -4
- data/lib/alephant/models/sequencer.rb +10 -0
- data/lib/alephant/version.rb +1 -1
- data/lib/alephant/views.rb +2 -2
- data/lib/env.rb +1 -1
- data/spec/logger_spec.rb +40 -0
- data/spec/spec_helper.rb +1 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df75578b70f5f4edee18315d47acdd5b446b319b
|
4
|
+
data.tar.gz: 7c21430e5949075f3fb2ea9db699a117a913ac77
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df985a135a85c1fd05f060c897c1e3408b3531d930cc2473862d06be1af3843ee7d54577e085fae4e2276a2abb2c3392d424a3a6308d7856c7125f82ec1ccdfb
|
7
|
+
data.tar.gz: 0ef61361d4139f8199437adee01356386c37553f261d9b129e262b886cf3cb28622007e0450d4d10207d3b2da628dd61e91ba393191349ff13caec6857c35659
|
data/README.md
CHANGED
@@ -50,10 +50,14 @@ opts = {
|
|
50
50
|
}
|
51
51
|
}
|
52
52
|
|
53
|
-
|
53
|
+
logger = Logger.new
|
54
|
+
|
55
|
+
thread = Alephant::Alephant.new(opts, logger).run!
|
54
56
|
thread.join
|
55
57
|
```
|
56
58
|
|
59
|
+
logger is optional, and must confirm to the Ruby standard logger interface
|
60
|
+
|
57
61
|
Provide a view in a folder:
|
58
62
|
|
59
63
|
```
|
data/alephant.gemspec
CHANGED
@@ -7,7 +7,7 @@ require 'alephant/version'
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = 'alephant'
|
9
9
|
s.version = Alephant::VERSION
|
10
|
-
s.date =
|
10
|
+
s.date = Time.now.strftime "%Y-%m-%d"
|
11
11
|
s.summary = "Static Publishing in the Cloud"
|
12
12
|
s.description = "Static publishing to S3 based on SQS messages"
|
13
13
|
s.authors = ["Robert Kenny"]
|
data/lib/alephant.rb
CHANGED
@@ -5,6 +5,7 @@ require 'json'
|
|
5
5
|
|
6
6
|
require_relative 'env'
|
7
7
|
|
8
|
+
require 'alephant/models/logger'
|
8
9
|
require 'alephant/models/queue'
|
9
10
|
require 'alephant/models/cache'
|
10
11
|
require 'alephant/models/renderer'
|
@@ -29,7 +30,8 @@ module Alephant
|
|
29
30
|
:set_last_seen_proc
|
30
31
|
]
|
31
32
|
|
32
|
-
def initialize(opts = {})
|
33
|
+
def initialize(opts = {}, logger = nil)
|
34
|
+
set_logger(logger)
|
33
35
|
set_opts(opts)
|
34
36
|
|
35
37
|
@sequencer = Sequencer.new(
|
@@ -44,6 +46,10 @@ module Alephant
|
|
44
46
|
@renderer = Renderer.new(@view_id, @view_path)
|
45
47
|
end
|
46
48
|
|
49
|
+
def set_logger(logger)
|
50
|
+
::Alephant.logger = logger
|
51
|
+
end
|
52
|
+
|
47
53
|
def parse(msg)
|
48
54
|
JSON.parse(msg)
|
49
55
|
end
|
@@ -5,18 +5,22 @@ module Alephant
|
|
5
5
|
attr_reader :id, :bucket, :path
|
6
6
|
|
7
7
|
def initialize(id, path)
|
8
|
+
@logger = ::Alephant.logger
|
8
9
|
@id = id
|
9
10
|
@path = path
|
10
11
|
|
11
12
|
s3 = AWS::S3.new
|
12
13
|
@bucket = s3.buckets[id]
|
14
|
+
@logger.info("Cache.initialize: end with id #{id} and path #{path}")
|
13
15
|
end
|
14
16
|
|
15
17
|
def put(id, data)
|
16
18
|
@bucket.objects["#{@path}/#{id}"].write(data)
|
19
|
+
@logger.info("Cache.put: #{@path}/#{id} and write data #{data}")
|
17
20
|
end
|
18
21
|
|
19
22
|
def get(id)
|
23
|
+
@logger.info("Cache.get: #{@path}/#{id}")
|
20
24
|
@bucket.objects["#{@path}/#{id}"].read
|
21
25
|
end
|
22
26
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
module Alephant
|
4
|
+
def self.logger
|
5
|
+
::Alephant::LogSystem.logger
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.logger=(value)
|
9
|
+
::Alephant::LogSystem.logger = value
|
10
|
+
end
|
11
|
+
|
12
|
+
class LogSystem
|
13
|
+
def self.logger
|
14
|
+
@logger ||= Logger.new(STDOUT)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.logger=(value)
|
18
|
+
@logger = value
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
@@ -5,13 +5,18 @@ module Alephant
|
|
5
5
|
attr_accessor :q
|
6
6
|
|
7
7
|
def initialize(id)
|
8
|
+
@logger = ::Alephant.logger
|
9
|
+
|
8
10
|
@sqs = AWS::SQS.new
|
9
11
|
@q = @sqs.queues[id]
|
10
12
|
|
11
13
|
unless @q.exists?
|
12
14
|
@q = @sqs.queues.create(id)
|
13
15
|
sleep_until_queue_exists
|
16
|
+
@logger.info("Queue.initialize: created queue with id #{id}")
|
14
17
|
end
|
18
|
+
|
19
|
+
@logger.info("Queue.initialize: ended with id #{id}")
|
15
20
|
end
|
16
21
|
|
17
22
|
def sleep_until_queue_exists
|
@@ -19,6 +24,7 @@ module Alephant
|
|
19
24
|
end
|
20
25
|
|
21
26
|
def poll(*args, &block)
|
27
|
+
@logger.info("Queue.poll: polling with arguments #{args}")
|
22
28
|
@q.poll(*args, &block)
|
23
29
|
end
|
24
30
|
end
|
@@ -8,11 +8,16 @@ module Alephant
|
|
8
8
|
attr_reader :id
|
9
9
|
|
10
10
|
def initialize(id, view_base_path=nil)
|
11
|
+
@logger = ::Alephant.logger
|
12
|
+
|
11
13
|
@id = id
|
12
14
|
self.base_path = view_base_path unless view_base_path.nil?
|
15
|
+
|
16
|
+
@logger.info("Renderer.initialize: end with self.base_path set to #{self.base_path}")
|
13
17
|
end
|
14
18
|
|
15
19
|
def render(data)
|
20
|
+
@logger.info("Renderer.render: rendered template with id #{id} and data #{data}")
|
16
21
|
Mustache.render(
|
17
22
|
template(@id),
|
18
23
|
model(@id,data)
|
@@ -27,30 +32,34 @@ module Alephant
|
|
27
32
|
if File.directory?(path)
|
28
33
|
@base_path = path
|
29
34
|
else
|
35
|
+
@logger.error("Renderer.base_path=(path): error of invalid view path #{path}")
|
30
36
|
raise Errors::InvalidViewPath
|
31
37
|
end
|
32
38
|
end
|
33
39
|
|
34
40
|
def model(id, data)
|
35
|
-
model_location =
|
36
|
-
File.join(base_path,'models',"#{id}.rb")
|
41
|
+
model_location = File.join(base_path, 'models', "#{id}.rb")
|
37
42
|
|
38
43
|
begin
|
39
44
|
require model_location
|
40
45
|
klass = ::Alephant::Views.get_registered_class(id)
|
46
|
+
@logger.info("Renderer.model: klass set to #{klass}")
|
41
47
|
rescue Exception => e
|
48
|
+
@logger.error("Renderer.model: view model with id #{id} not found")
|
42
49
|
raise Errors::ViewModelNotFound
|
43
50
|
end
|
44
51
|
|
52
|
+
@logger.info("Renderer.model: creating new klass with data #{data}")
|
45
53
|
klass.new(data)
|
46
54
|
end
|
47
55
|
|
48
56
|
def template(id)
|
49
|
-
template_location =
|
50
|
-
File.join(base_path,'templates',"#{id}.mustache")
|
57
|
+
template_location = File.join(base_path,'templates',"#{id}.mustache")
|
51
58
|
begin
|
59
|
+
@logger.info("Renderer.template: #{template_location}")
|
52
60
|
File.open(template_location).read
|
53
61
|
rescue Exception => e
|
62
|
+
@logger.error("Renderer.template: view tempalte with id #{id} not found")
|
54
63
|
raise Errors::ViewTemplateNotFound
|
55
64
|
end
|
56
65
|
end
|
@@ -18,6 +18,8 @@ module Alephant
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def initialize(opts, id)
|
21
|
+
@logger = ::Alephant.logger
|
22
|
+
|
21
23
|
dynamo_db = AWS::DynamoDB.new
|
22
24
|
|
23
25
|
@id = id
|
@@ -28,6 +30,8 @@ module Alephant
|
|
28
30
|
begin
|
29
31
|
sleep_until_table_active
|
30
32
|
rescue AWS::DynamoDB::Errors::ResourceNotFoundException
|
33
|
+
@logger.error("Sequencer.initialize: DynamoDB resource was not found.")
|
34
|
+
|
31
35
|
@table = dynamo_db.tables.create(
|
32
36
|
@table_name,
|
33
37
|
@table_conf[:read_units],
|
@@ -35,8 +39,12 @@ module Alephant
|
|
35
39
|
@table_conf[:schema]
|
36
40
|
)
|
37
41
|
|
42
|
+
@logger.info("Sequencer.initialize: Creating table with name #{@table_name}, read units #{@table_conf[:read_units]}, write units #{@table_conf[:write_units]}, schema #{@table_conf[:schema]}")
|
43
|
+
|
38
44
|
sleep_until_table_active
|
39
45
|
end
|
46
|
+
|
47
|
+
@logger.info("Sequencer.initialize: end with id #{@id}")
|
40
48
|
end
|
41
49
|
|
42
50
|
def sequential?(data)
|
@@ -53,6 +61,7 @@ module Alephant
|
|
53
61
|
batch = AWS::DynamoDB::BatchWrite.new
|
54
62
|
batch.put(@table_name, [:key => @id,:value => last_seen_id])
|
55
63
|
batch.process!
|
64
|
+
@logger.info("Sequencer.set_last_seen: id #{id} and last_seen_id #{last_seen_id}")
|
56
65
|
end
|
57
66
|
|
58
67
|
def get_last_seen
|
@@ -65,6 +74,7 @@ module Alephant
|
|
65
74
|
}
|
66
75
|
).first["value"].to_i
|
67
76
|
rescue
|
77
|
+
@logger.error("Sequencer.get_last_seen: id #{id}")
|
68
78
|
0
|
69
79
|
end
|
70
80
|
end
|
data/lib/alephant/version.rb
CHANGED
data/lib/alephant/views.rb
CHANGED
data/lib/env.rb
CHANGED
data/spec/logger_spec.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Alephant::LogSystem do
|
4
|
+
before(:each) do
|
5
|
+
sequencer = double()
|
6
|
+
queue = double()
|
7
|
+
cache = double()
|
8
|
+
renderer = double()
|
9
|
+
|
10
|
+
Alephant::Sequencer.any_instance.stub(:initialize).and_return(sequencer)
|
11
|
+
Alephant::Queue.any_instance.stub(:initialize).and_return(queue)
|
12
|
+
Alephant::Cache.any_instance.stub(:initialize).and_return(cache)
|
13
|
+
Alephant::Renderer.any_instance.stub(:initialize).and_return(renderer)
|
14
|
+
end
|
15
|
+
|
16
|
+
after(:each) do
|
17
|
+
Alephant.logger = nil
|
18
|
+
end
|
19
|
+
|
20
|
+
let (:instance) { Alephant::Alephant }
|
21
|
+
subject { Alephant::LogSystem }
|
22
|
+
|
23
|
+
describe "::Alephant::LogSystem.logger" do
|
24
|
+
context "Logger not provided" do
|
25
|
+
it "return Ruby built-in Logger" do
|
26
|
+
instance.new
|
27
|
+
expect(Alephant.logger.class).to be(Logger)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "Logger provided" do
|
32
|
+
it "return custom Logger" do
|
33
|
+
class FakeLogger; end
|
34
|
+
instance.new({}, FakeLogger.new)
|
35
|
+
expect(Alephant.logger.class).to be(FakeLogger)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alephant
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- Robert Kenny
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -171,6 +171,7 @@ files:
|
|
171
171
|
- lib/alephant/errors/view_model_not_found.rb
|
172
172
|
- lib/alephant/errors/view_template_not_found.rb
|
173
173
|
- lib/alephant/models/cache.rb
|
174
|
+
- lib/alephant/models/logger.rb
|
174
175
|
- lib/alephant/models/queue.rb
|
175
176
|
- lib/alephant/models/renderer.rb
|
176
177
|
- lib/alephant/models/sequencer.rb
|
@@ -183,6 +184,7 @@ files:
|
|
183
184
|
- spec/cache_spec.rb
|
184
185
|
- spec/fixtures/views/models/example.rb
|
185
186
|
- spec/fixtures/views/templates/example.mustache
|
187
|
+
- spec/logger_spec.rb
|
186
188
|
- spec/queue_spec.rb
|
187
189
|
- spec/renderer_spec.rb
|
188
190
|
- spec/sequencer_spec.rb
|
@@ -216,6 +218,7 @@ test_files:
|
|
216
218
|
- spec/cache_spec.rb
|
217
219
|
- spec/fixtures/views/models/example.rb
|
218
220
|
- spec/fixtures/views/templates/example.mustache
|
221
|
+
- spec/logger_spec.rb
|
219
222
|
- spec/queue_spec.rb
|
220
223
|
- spec/renderer_spec.rb
|
221
224
|
- spec/sequencer_spec.rb
|