Skip to content

Instantly share code, notes, and snippets.

@kleinschmidt
Last active August 29, 2015 14:08
Show Gist options
  • Save kleinschmidt/0bb1540b8255eb971477 to your computer and use it in GitHub Desktop.
Save kleinschmidt/0bb1540b8255eb971477 to your computer and use it in GitHub Desktop.
Tiny demo of using Amazon SQS to listen to notifications from Mechanical Turk. Run `npm install` to get dependencies.
{
"accessKey": "your access key",
"secretKey": "your secret key"
}
{
"Turker": {
"sqs_queue_url": "https://sqs.us-west-2.amazonaws.com/<some kind of ID>/<queue_name>"
}
}
{
"name": "sqs-test",
"version": "0.0.1",
"private": true,
"dependencies": {
"sqs": "~1.2.0",
"mturk": "git+https://github.com/kleinschmidt/mturk.git#dfk/sendtestnotification"
}
}
var creds = require('./aws_creds.json');
var mturk = require('mturk')({ creds: creds, sandbox: true });
var config = require('./config.json');
var sqs_queue_url = config.Turker.sqs_queue_url;
var test_event_type = ['AssignmentAbandoned'];
var test_notification = {
Destination: sqs_queue_url,
Transport: 'SQS',
Version: '2006-05-05',
EventType: test_event_type
};
console.log('Sending Notification:\n', test_notification);
mturk.SendTestEventNotification({
Notification: test_notification,
TestEventType: test_event_type
}, console.log);
// receive messages
var sqs = require('sqs');
var queue = sqs({ access: creds.accessKey,
secret: creds.secretKey,
region: 'us-west-2' });
queue.pull('HLPTurk_test', function(message, callback) {
console.log('Notification received:\n', message);
// remove message from queue and pull again:
callback();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment