Created
April 14, 2014 18:03
-
-
Save cadecairos/10670006 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1. COPY TO LOGIN.WEBMAKER.ORG ROOT DIRECTORY | |
// 2. RUN `NPM INSTALL AWS-SDK` | |
// 3. RUN `SQS_QUEUE_REGION=<QUEUE_REGION> SQS_QUEUE_URL=<QUEUE_URL> node create_user_log.js | |
// 4. RUN `RM -R NODE_MODULES/AWS-SDK` | |
var env = require( "./config/environment" ); | |
var db, | |
dbOptions = {}; | |
// DB Config parsing | |
db = env.get("DB"); | |
dbOptions = env.get("DBOPTIONS"); | |
var Sequelize = require( "sequelize" ) | |
var sequelize = new Sequelize( db.database, db.username, db.password, dbOptions ); | |
var User = sequelize.import( __dirname + "/app/models/user/sqlModel.js" ); | |
var AWS = require("aws-sdk"); | |
var async = require("async"); | |
var sqs = new AWS.SQS({ | |
region: process.env.SQS_QUEUE_REGION | |
}); | |
function hatchetDoppleganger(event_type, timestamp, data, cb) { | |
if (typeof data !== "object") { | |
return; | |
} | |
if (!process.env.SQS_QUEUE_URL) { | |
return; | |
} | |
var wrapper = { | |
app: "login", | |
event_type: event_type, | |
timestamp: timestamp, | |
data: data | |
}; | |
var body = JSON.stringify(wrapper); | |
sqs.sendMessage({ | |
MessageBody: body, | |
QueueUrl: process.env.SQS_QUEUE_URL | |
}, cb); | |
} | |
User.findAll().success(function(users){ | |
async.eachSeries( users, function(user, cb) { | |
hatchetDoppleganger("create_user", (new Date(user.getDataValue("createdAt"))).toISOString(), { | |
userId: user.getDataValue("id"), | |
username: user.getDataValue("username"), | |
email: user.getDataValue("email"), | |
subscribeToWebmakerList: false, | |
sendNewUserEmail: false | |
}, cb); | |
}, function(err) { | |
if ( err ) { | |
console.log(err); | |
process.exit(1) | |
} | |
console.log( "Completed pushing " + users.length + " User Creation Events to " + process.env.SQS_QUEUE_URL ); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment