Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 20 additions & 66 deletions bots/s3-load-trigger/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function listFilesFromKey(bucket, lastkey, opts, callback) {
StartAfter: lastkey.toString(),
MaxKeys: opts.limit,
Prefix: opts.prefix
}, function (err, data) {
}, function(err, data) {
if (err) {
callback(err);
} else {
Expand All @@ -46,74 +46,28 @@ exports.handler = (event, context, callback) => {
};
console.log(configure);
console.log("Triggered By Event", JSON.stringify(event));
dynamodb.getSetting(setting_id, (err, data) => {
if (err) {
callback(err);
} else {
let position = data && data.value || "";
console.log("Position:", position);
listFilesFromKey(bucket, position, opts, function (err, files) {
if (err) {
console.log(err);
callback(err);
} else {
if (files.length == 0) {
console.log("No new Files");
callback();
return;
}

console.log(files);
let files = event.Records.map(r => ({ bucket: r.s3.bucket.name, key: r.s3.object.key }));
var lastKey = files[files.length - 1].key;

// var firstKey = files[0].Key;
var lastKey = files[files.length - 1].Key;

var stream = leo.load("Leo_core_s3_load_trigger", "commands.s3_bus_load", {
debug: true
});
stream.write({
payload: {
command: "load",
files: files.map(file => {
return {
bucket: bucket,
key: file.Key
};
})
}
});
stream.end((err) => {
if (err) {
callback(err);
} else {
dynamodb.saveSetting(setting_id, lastKey, function () {
callback();
});
}
});
console.log(files);
var stream = leo.load("Leo_core_s3_load_trigger", "commands.s3_bus_load", {
debug: true
});

// processing.single("commands.s3_bus_load", {
// command: "load",
// files: files.map(file => {
// return {
// bucket: bucket,
// key: file.Key
// };
// })
// }, {
// correlation_id: {
// source: bucket,
// start: `${firstKey}`,
// end: `${lastKey}`
// },
// forceDynamoDB: true,
// id: "Leo_core_s3_load_trigger"
// }).then((response) => {
// dynamodb.saveSetting(setting_id, lastKey, function () {
// callback();
// });
// }).catch(callback);
}
stream.write({
payload: {
command: "load",
files: files
}
});
stream.end((err) => {
if (err) {
callback(err);
} else {
console.log("Last Key:", lastKey);
dynamodb.saveSetting(setting_id, lastKey, function() {
callback();
});
}
});
Expand Down