Last active
August 29, 2015 14:08
-
-
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.
This file contains 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
{ | |
"accessKey": "your access key", | |
"secretKey": "your secret key" | |
} |
This file contains 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
{ | |
"Turker": { | |
"sqs_queue_url": "https://sqs.us-west-2.amazonaws.com/<some kind of ID>/<queue_name>" | |
} | |
} |
This file contains 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
{ | |
"name": "sqs-test", | |
"version": "0.0.1", | |
"private": true, | |
"dependencies": { | |
"sqs": "~1.2.0", | |
"mturk": "git+https://github.com/kleinschmidt/mturk.git#dfk/sendtestnotification" | |
} | |
} |
This file contains 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
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