-
Notifications
You must be signed in to change notification settings - Fork 17
/
simpledb.js
49 lines (41 loc) · 1.32 KB
/
simpledb.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
var utils = require('./utils');
var Promise = require('bluebird');
var AWS = require('aws-sdk');
var config = require('./config.json').store.simpledb;
var createDomain = function() {
var simpledb = new AWS.SimpleDB(utils.getRegionObject());
return simpledb.createDomain({ DomainName: config.domain }).promise();
};
var deleteDomain = function() {
var simpledb = new AWS.SimpleDB(utils.getRegionObject());
return simpledb.deleteDomain({ DomainName: config.domain }).promise();
};
var isInstanceToBeProcessed = function(instance, eventTimestamp) {
var simpledb = new AWS.SimpleDB(utils.getRegionObject());
var key = instance + eventTimestamp;
return simpledb.getAttributes({
DomainName: config.domain,
ItemName: key,
AttributeNames: [ 'processed' ],
ConsistentRead: true
})
.promise()
.then(function(data) {
return data.Attributes === undefined;
});
};
var markInstanceAsProcessed = function(instance, eventTimestamp) {
var simpledb = new AWS.SimpleDB(utils.getRegionObject());
var key = instance + eventTimestamp;
return simpledb.putAttributes({
DomainName: config.domain,
ItemName: key,
Attributes: [
{
Name: 'processed',
Value: 'true'
}
]
}).promise();
};
module.exports = { createDomain, deleteDomain, isInstanceToBeProcessed, markInstanceAsProcessed};