Skip to content

Instantly share code, notes, and snippets.

@jreece1567
Created April 5, 2016 01:47
Show Gist options
  • Save jreece1567/edda20061ee058a2dd4a05a4be9e6a10 to your computer and use it in GitHub Desktop.
Save jreece1567/edda20061ee058a2dd4a05a4be9e6a10 to your computer and use it in GitHub Desktop.

Sitemap Service

Collects SNS messages from Westfield API's, stores them in redis, and then get requests to the service generate url's on the fly.

Running in development

Sitemap service uses Redis to store records for all products, events, stores, retailers, and deals. You will need redis installed. Easiest with brew.

$ brew install redis
$ redis-server
$ bundle install 
$ rails s

Backfill some data.

You can use the rake tasks to backfill data to redis. Each country uses it's own database. The rake tasks will dump into each accordingly. The schema is as follows.

db 0 = AU
db 1 = UK
db 2 = US
db 3 = NZ 
db 4 = Maps index and Resque queue. 

Products is extremely large, and I wouldn't recommend using the rake task for devleopment.

$ rake get_deals:map
$ rake get_stores:map
$ rake get_events:map
$ rake get_deals:map

Once the you have some sample data, you will need to generate the sitemap index.

$ rake index:map

In development everything will be processed though posting to the /map route. In production all posts and rake tasks are handled by Resque in the jobs folder.

Using the service.

Posting

You can manually post to the maps controller to populate data. the post will need to include a a custom token as we are verifying sns messages to ensure they are coming form amazon. the request raw post needs to look something like this. The Type, token, and message fields need to be there for development. Format precise, and this token is needed.

localhost:3000/map
{
  "Type" : "Notification",
  "Token" : "^&6NC0$tU7i5%Hy^#2HB#%98gp8Tb@",
  "Subject" : "Testing publish to subscribed queues",
  "Message" : "{\"sender\":\"store-service-uat\",\"type\":\"store_update\",\"data\":{\"uri\":\"https://api.westfield.io/stores/56900\",\"id\":56900}}"
}     

Getting the maps

Open a browser, and go to the index. substitute country in the url to see the index for each country.

http://localhost:3000/map/au/sitemapindex.xml

Copy the relative link in the index and append to local host.

http://localhost:3000/map/au/deals1.xml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment