# Alephant::Publisher::Queue Static publishing to S3 based on SQS messages. [![Build Status](https://travis-ci.org/BBC-News/alephant-publisher-queue.png?branch=master)](https://travis-ci.org/BBC-News/alephant-publisher-queue) [![Dependency Status](https://gemnasium.com/BBC-News/alephant-publisher-queue.png)](https://gemnasium.com/BBC-News/alephant-publisher-queue) [![Gem Version](https://badge.fury.io/rb/alephant-publisher-queue.png)](http://badge.fury.io/rb/alephant-publisher-queue) ## Dependencies - JRuby 1.7.8+ - An AWS account, with: - S3 bucket. - SQS Queue. - Dynamo DB table. ## Migrating from [Alephant::Publisher](https://github.com/BBC-News/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: ```yaml 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** ```ruby class Foo < Alephant::Views::Base def content @data['content'] end end ``` **foo.mustache** ``` {{ content }} ``` ## Usage ```ruby require "alephant/logger" require "alephant/publisher/queue" module MyApp def self.run! loop do Alephant::Publisher::Queue.create(options).run! rescue => e Alephant::Logger.get_logger.warn "Error: #{e.message}" end end private def self.options 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: ```json { "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](https://github.com/BBC-News/alephant-preview) allows you to see the HTML generated by your templates, both standalone and in the context of a page. ## Contributing 1. [Fork it!](http://github.com/BBC-News/alephant-publisher-queue/fork) 2. Create your feature branch: `git checkout -b my-new-feature` 3. Commit your changes: `git commit -am 'Add some feature'` 4. Push to the branch: `git push origin my-new-feature` 5. Create new [Pull Request](https://github.com/BBC-News/alephant-publisher-queue/compare). Feel free to create an [issue](https://github.com/BBC-News/alephant-publisher-queue/issues/new) if you find a bug.