Skip to content

Commit eb89d97

Browse files
add polling source for shared drives
1 parent cdd0ddb commit eb89d97

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import googleDrive from "../../google_drive.app.mjs";
2+
import sourceComponent from "../new-files-instant/new-files-instant.mjs";
3+
import sampleEmit from "../new-files-instant/test-event.mjs";
4+
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
5+
6+
export default {
7+
key: "google_drive-new-files-shared-drive",
8+
name: "New Files (Shared Drive)",
9+
description: "Emit new event when a new file is added in your shared Google Drive",
10+
version: "0.0.1",
11+
type: "source",
12+
dedupe: "unique",
13+
props: {
14+
googleDrive,
15+
db: "$.service.db",
16+
timer: {
17+
label: "Polling interval",
18+
description: "Interval to poll the Google Drive API for new files",
19+
type: "$.interface.timer",
20+
default: {
21+
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
22+
},
23+
},
24+
drive: {
25+
propDefinition: [
26+
googleDrive,
27+
"sharedDrive",
28+
],
29+
description: "Select a [Shared Drive](https://support.google.com/a/users/answer/9310351) from this list",
30+
optional: false,
31+
},
32+
folders: sourceComponent.props.folders,
33+
},
34+
hooks: {
35+
async deploy() {
36+
// Get initial page token for change tracking
37+
const startPageToken = await this.googleDrive.getPageToken(this.getDriveId());
38+
this._setPageToken(startPageToken);
39+
this._setLastFileCreatedTime(Date.now());
40+
41+
// Emit the most recent files
42+
await sourceComponent.hooks.deploy.bind(this)();
43+
},
44+
},
45+
methods: sourceComponent.methods,
46+
async run() {
47+
const pageToken = this._getPageToken();
48+
49+
const driveId = this.getDriveId();
50+
const changedFilesStream = this.googleDrive.listChanges(pageToken, driveId);
51+
for await (const changedFilesPage of changedFilesStream) {
52+
const { nextPageToken } = changedFilesPage;
53+
54+
// Process all the changed files retrieved from the current page
55+
await this.processChanges();
56+
57+
// After successfully processing the changed files, we store the page
58+
// token of the next page
59+
this._setPageToken(nextPageToken);
60+
}
61+
},
62+
sampleEmit,
63+
};

0 commit comments

Comments
 (0)