Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
vtalas committed Feb 29, 2024
1 parent 46c7e8d commit 7a02c26
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
17 changes: 5 additions & 12 deletions src/appmixer/google/drive/NewFile/NewFile.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const Promise = require('bluebird');
const moment = require('moment');
const { google } = require('googleapis');
const commons = require('../drive-commons');
Expand Down Expand Up @@ -38,36 +37,29 @@ const detectNewFiles = async function(context) {
try {
lock = await context.lock(context.componentId, { maxRetryCount: 0 });
} catch (err) {
context.log({ stage: 'lock error' });
await context.stateSet('hasSkippedMessage', true);
return context.response();
}

try {

const { startPageToken, lastChangeFileIDs = {}, processedFiles = [] } = await context.loadState();

const { startPageToken, processedFiles = [] } = await context.loadState();
const auth = commons.getOauth2Client(context.auth);
const drive = google.drive({ version: 'v3', auth });

const { newFiles, newStartPageToken } = await getNewFiles(lock, drive, folder.id, startPageToken);

await context.stateSet('hasSkippedMessage', false);

const processedFilesSet = x(processedFiles);
const processedFilesSet = commons.processedItemsBuffer(processedFiles);

for (let file of newFiles) {
lastChangeFileIDs[file.name] = lastChangeFileIDs[file.name] || [];
lastChangeFileIDs[file.name].push(newStartPageToken);
if (!processedFilesSet.has(file.id)) {
processedFilesSet.add(newStartPageToken, file.id)
lastChangeFileIDs[file.name].push('triggered!!!!');
processedFilesSet.add(newStartPageToken, file.id);
await context.sendJson(file, 'file');
}
}

await context.stateSet('startPageToken', newStartPageToken);
await context.stateSet('lastChangeFileIDs', lastChangeFileIDs);
await context.stateSet('processedFiles', processedFilesSet.export());

} finally {
Expand Down Expand Up @@ -112,7 +104,8 @@ module.exports = {
const { expiration, hasSkippedMessage } = await context.loadState();

if (hasSkippedMessage) {
context.log({ stage: 'XXXXXXXXXXXXXXXXXXXXX', });
// a message came when we were processing results,
// we have to check for new files again
await detectNewFiles(context);
}

Expand Down
5 changes: 2 additions & 3 deletions src/appmixer/google/drive/drive-commons.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ let defaultExportFormats = {
}
};

const x = function(data = []) {
const processedItemsBuffer = function(data = []) {

const MAX_GROUP_COUNT = 3;
return {
Expand All @@ -43,13 +43,12 @@ const x = function(data = []) {
export() {
return data.slice(-MAX_GROUP_COUNT);
}

};
};

module.exports = {

x,
processedItemsBuffer,
defaultExportFormats,

getOauth2Client(auth) {
Expand Down

0 comments on commit 7a02c26

Please sign in to comment.