File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ node_modules
Original file line number Diff line number Diff line change 1+ {
2+ "node" : true ,
3+ "esnext" : true ,
4+ "unused" : true
5+ }
Original file line number Diff line number Diff line change 1+ ## FastBoot S3 Notifier
2+
3+ This notifier for the [ FastBoot App Server] [ app-server ] works with AWS
4+ S3 to poll an object's Last Modified header to detect when you have
5+ deployed a new version of your app.
6+
7+ To use the notifier, configure it with an S3 bucket and key:
8+
9+ ``` js
10+ const S3Notifier = require (' fastboot-s3-notifier' );
11+
12+ let notifier = new S3Notifier ({
13+ bucket: S3_BUCKET ,
14+ key: S3_KEY
15+ });
16+
17+ let server = new FastBootAppServer ({
18+ notifier: notifier
19+ });
20+ ```
21+
22+ When the notifier starts, it will poll the object at the specified
23+ bucket and key. Once the ` LastModified ` metadata changes, it will tell
24+ the FastBoot App Server to fetch the latest version of the app.
25+
26+ Note that you should point the notifier at a _ static_ path on S3, like
27+ ` fastboot-deploy-info.json ` . That JSON file should then point the app
28+ server to the latest application bundle. This way, you don't have to
29+ propagate configuration changes to all of your app servers, and they can
30+ poll a single key in perpetuity.
31+
32+ If you like this, you may also be interested in the companion
33+ [ fastboot-s3-downloader] ( https://github.com/tomdale/fastboot-s3-downloader ) ,
34+ which parses the above-described JSON file to find and download the
35+ latest version of your app.
Original file line number Diff line number Diff line change 1+ "use strict" ;
2+
3+ const AWS = require ( 'aws-sdk' ) ;
4+
5+ const DEFAULT_POLL_TIME = 3 * 1000 ;
6+
7+ const s3 = new AWS . S3 ( {
8+ apiVersion : '2006-03-01'
9+ } ) ;
10+
11+ class S3Notifier {
12+ constructor ( options ) {
13+ this . ui = options . ui ;
14+ this . bucket = options . bucket ;
15+ this . key = options . key ;
16+ this . pollTime = options . poll || DEFAULT_POLL_TIME ;
17+
18+ this . params = {
19+ Bucket : this . bucket ,
20+ Key : this . key
21+ } ;
22+ }
23+
24+ subscribe ( notify ) {
25+ this . notify = notify ;
26+
27+ this . getCurrentLastModified ( )
28+ . then ( ( ) => this . schedulePoll ( ) ) ;
29+ }
30+
31+ getCurrentLastModified ( ) {
32+ return s3 . headObject ( this . params ) . promise ( )
33+ . then ( data => {
34+ this . lastModified = data . LastModified ;
35+ } )
36+ . catch ( ( ) => {
37+ this . ui . writeError ( 'error fetching S3 last modified; notifications disabled' ) ;
38+ } ) ;
39+ }
40+
41+ schedulePoll ( ) {
42+ setTimeout ( ( ) => {
43+ this . poll ( ) ;
44+ } , this . pollTime ) ;
45+ }
46+
47+ poll ( ) {
48+ s3 . headObject ( this . params ) . promise ( )
49+ . then ( data => {
50+ this . compareLastModifieds ( data . LastModified ) ;
51+ this . schedulePoll ( ) ;
52+ } ) ;
53+ }
54+
55+ compareLastModifieds ( newLastModified ) {
56+ if ( newLastModified !== this . lastModified ) {
57+ this . ui . writeLine ( 'config modified; old=%s; new=%s' , this . lastModified , newLastModified ) ;
58+ this . lastModified = newLastModified ;
59+ this . notify ( ) ;
60+ }
61+ }
62+ }
63+
64+
65+ module . exports = S3Notifier ;
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " fastboot-s3-notifier" ,
3+ "version" : " 0.1.0" ,
4+ "description" : " A FastBoot App Server notifier for AWS S3" ,
5+ "main" : " index.js" ,
6+ "scripts" : {
7+ "test" : " mocha"
8+ },
9+ "repository" : {
10+ "type" : " git" ,
11+ "url" : " git+https://github.com/tomdale/fastboot-s3-notifier.git"
12+ },
13+ "keywords" : [
14+ " ember" ,
15+ " fastboot" ,
16+ " notifier" ,
17+ " s3"
18+ ],
19+ "author" :
" Tom Dale <[email protected] >" ,
20+ "license" : " MIT" ,
21+ "bugs" : {
22+ "url" : " https://github.com/tomdale/fastboot-s3-notifier/issues"
23+ },
24+ "homepage" : " https://github.com/tomdale/fastboot-s3-notifier#readme" ,
25+ "dependencies" : {
26+ "aws-sdk" : " ^2.3.4"
27+ }
28+ }
You can’t perform that action at this time.
0 commit comments