Alephant::Publisher::Queue
Static publishing to S3 based on SQS messages.
Dependencies
- JRuby 1.7.8+
- An AWS account, with:
- S3 bucket.
- SQS Queue.
- Dynamo DB table.
Migrating from Alephant::Publisher
Add the new gem in your Gemfile:
gem 'alephant-publisher-queue'
Run:
bundle install
Require the new gem in your app:
require 'alephant/publisher/queue'
Important - note that the namespace has changed from Alephant::Publisher
to Alephant::Publisher::Queue
.
Installation
Add this line to your application's Gemfile:
gem 'alephant-publisher-queue'
And then execute:
bundle
Or install it yourself as:
gem install alephant-publisher-queue
Setup
Ensure you have a config/aws.yml
in the format:
access_key_id: ACCESS_KEY_ID
secret_access_key: SECRET_ACCESS_KEY
Structure
Provide a view and template:
└── views
├── models
│ └── foo.rb
└── templates
└── foo.mustache
foo.rb
class Foo < Alephant::Views::Base
def content
@data['content']
end
end
foo.mustache
{{ content }}
Usage
require "alephant/logger"
require "alephant/publisher/queue"
module MyApp
def self.run!
loop do
Alephant::Publisher::Queue.create().run!
rescue => e
Alephant::Logger.get_logger.warn "Error: #{e.}"
end
end
private
def self.
Alephant::Publisher::Queue::Options.new.tap do |opts|
opts.add_queue(
:aws_account_id => 'example',
:sqs_queue_name => 'test_queue'
)
opts.add_writer(
:keep_all_messages => 'false',
:lookup_table_name => 'lookup-dynamo-table',
:renderer_id => 'renderer-id',
:s3_bucket_id => 'bucket-id',
:s3_object_path => 'example-s3-path',
:sequence_id_path => '$.sequential_id',
:sequencer_table_name => 'sequence-dynamo-table',
:view_path => 'path/to/views'
)
end
end
end
Add a message to your SQS queue, with the following format:
{
"content": "Hello World!",
"sequential_id": 1
}
Output:
Hello World!
S3 Path:
S3 / bucket-id / example-s3-path / renderer-id / foo / 7e0c33c476b1089500d5f172102ec03e / 1
Preview Server
Alephant Preview allows you to see the HTML generated by your templates, both standalone and in the context of a page.
Contributing
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Create new Pull Request.
Feel free to create an issue if you find a bug.