Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incremental sync #201

Merged
merged 7 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
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
10 changes: 10 additions & 0 deletions packages/@runlightyear/airtable/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# @runlightyear/airtable

## 1.2.14

### Patch Changes

- Updated dependencies [f723e889d]
- Updated dependencies [18e743421]
- Updated dependencies [3e7c405bd]
- Updated dependencies [86e21087b]
- @runlightyear/lightyear@1.19.0

## 1.2.13

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/@runlightyear/airtable/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@runlightyear/airtable",
"version": "1.2.13",
"version": "1.2.14",
"publishConfig": {
"access": "public"
},
Expand Down
10 changes: 10 additions & 0 deletions packages/@runlightyear/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# @runlightyear/cli

## 1.6.3

### Patch Changes

- Updated dependencies [f723e889d]
- Updated dependencies [18e743421]
- Updated dependencies [3e7c405bd]
- Updated dependencies [86e21087b]
- @runlightyear/lightyear@1.19.0

## 1.6.2

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/@runlightyear/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@runlightyear/cli",
"version": "1.6.2",
"version": "1.6.3",
"publishConfig": {
"access": "public"
},
Expand Down
10 changes: 10 additions & 0 deletions packages/@runlightyear/gcal/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# @runlightyear/gcal

## 0.11.14

### Patch Changes

- Updated dependencies [f723e889d]
- Updated dependencies [18e743421]
- Updated dependencies [3e7c405bd]
- Updated dependencies [86e21087b]
- @runlightyear/lightyear@1.19.0

## 0.11.13

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/@runlightyear/gcal/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@runlightyear/gcal",
"version": "0.11.13",
"version": "0.11.14",
"publishConfig": {
"access": "public"
},
Expand Down
10 changes: 10 additions & 0 deletions packages/@runlightyear/github/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# @runlightyear/github

## 1.3.14

### Patch Changes

- Updated dependencies [f723e889d]
- Updated dependencies [18e743421]
- Updated dependencies [3e7c405bd]
- Updated dependencies [86e21087b]
- @runlightyear/lightyear@1.19.0

## 1.3.13

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/@runlightyear/github/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@runlightyear/github",
"version": "1.3.13",
"version": "1.3.14",
"publishConfig": {
"access": "public"
},
Expand Down
10 changes: 10 additions & 0 deletions packages/@runlightyear/gmail/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# @runlightyear/gmail

## 0.6.15

### Patch Changes

- Updated dependencies [f723e889d]
- Updated dependencies [18e743421]
- Updated dependencies [3e7c405bd]
- Updated dependencies [86e21087b]
- @runlightyear/lightyear@1.19.0

## 0.6.14

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/@runlightyear/gmail/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@runlightyear/gmail",
"version": "0.6.14",
"version": "0.6.15",
"publishConfig": {
"access": "public"
},
Expand Down
10 changes: 10 additions & 0 deletions packages/@runlightyear/gsheets/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# @runlightyear/gsheets

## 0.8.14

### Patch Changes

- Updated dependencies [f723e889d]
- Updated dependencies [18e743421]
- Updated dependencies [3e7c405bd]
- Updated dependencies [86e21087b]
- @runlightyear/lightyear@1.19.0

## 0.8.13

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/@runlightyear/gsheets/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@runlightyear/gsheets",
"version": "0.8.13",
"version": "0.8.14",
"publishConfig": {
"access": "public"
},
Expand Down
9 changes: 9 additions & 0 deletions packages/@runlightyear/lightyear/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# @runlightyear/lightyear

## 1.19.0

### Minor Changes

- f723e889d: Use new finish sync api
- 18e743421: Do not maintain log history when streaming logs back to server
- 3e7c405bd: Catch http request errors and print the body before the end of a run
- 86e21087b: Initial retry logic for http and base requests

## 1.18.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/@runlightyear/lightyear/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@runlightyear/lightyear",
"version": "1.18.0",
"version": "1.19.0",
"publishConfig": {
"access": "public"
},
Expand Down
32 changes: 27 additions & 5 deletions packages/@runlightyear/lightyear/src/base/baseRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface BaseRequestProps {
[key: string]: any;
};
suppressLogs?: boolean;
maxRetries?: number;
}

/**
Expand All @@ -24,13 +25,16 @@ export interface BaseRequestProps {
* @param uri
* @param params
* @param data
* @param suppressLogs
* @param maxRetries
*/
export default async function baseRequest({
method = "POST",
uri,
params,
data,
suppressLogs = false,
maxRetries = 3,
}: BaseRequestProps): Promise<Response> {
if (!suppressLogs) console.debug("in baseRequest");

Expand Down Expand Up @@ -58,13 +62,31 @@ export default async function baseRequest({
if (!suppressLogs) console.debug(`baseRequest url: ${url}`);
if (!suppressLogs) console.debug("baseRequest props", props);

const response = await fetch(url, props);
let attempt = 0;
let response: Response | undefined;

if (!response.ok) {
throw new BaseRequestError(response);
while (attempt < maxRetries) {
response = await fetch(url, props);

if (!response.ok) {
if (response.status >= 500) {
attempt += 1;

if (!suppressLogs)
console.debug(`Retrying after ${response.status} error (${attempt})`);

continue;
}

throw new BaseRequestError(response);
}

if (!suppressLogs) console.debug("about to return from baseRequest");

return response;
}

if (!suppressLogs) console.debug("about to return from baseRequest");
invariant(response, "Missing response");

return response;
throw new BaseRequestError(response);
}
15 changes: 15 additions & 0 deletions packages/@runlightyear/lightyear/src/base/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -570,3 +570,18 @@ export async function detectHardDeletes(props: DetectHardDeletesProps) {
},
});
}

export interface FinishSyncProps {
collectionName: string;
syncId: string;
}

export async function finishSync(props: FinishSyncProps) {
const envName = getEnvName();
const { collectionName, syncId } = props;

return baseRequest({
method: "POST",
uri: `/api/v1/envs/${envName}/collections/${collectionName}/syncs/${syncId}/finish`,
});
}
4 changes: 3 additions & 1 deletion packages/@runlightyear/lightyear/src/base/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface HttpProxyRequestProps {
data?: object;
body?: string;
redactKeys?: string[];
maxRetries?: number;
}

/**
Expand Down Expand Up @@ -69,11 +70,12 @@ export interface HttpRequest {
}

export const httpRequest: HttpRequest = async (props) => {
const { redactKeys, ...rest } = props;
const { redactKeys, maxRetries, ...rest } = props;

const response = await baseRequest({
uri: "/api/v1/httpRequest",
data: rest,
maxRetries,
});

const parsedUrl = new URL(props.url);
Expand Down
10 changes: 5 additions & 5 deletions packages/@runlightyear/lightyear/src/base/syncAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { CollectionSynchronizer } from "../synchronizers/CollectionSynchronizer"
import { AppName, defineAction } from "./action";
import { AuthData } from "./auth";
import { AuthConnector } from "../connectors/AuthConnector";
import { startSync, updateSync } from "./collection";
import { finishSync, startSync, updateSync } from "./collection";
import { dayjsUtc } from "../util/dayjsUtc";

export interface ConnectorProps {
Expand Down Expand Up @@ -158,12 +158,12 @@ export function defineSyncAction(props: DefineSyncActionProps) {

try {
await synchronizer.sync(sync.id, props.direction);
await updateSync({
collection: props.collection,
const response = await finishSync({
collectionName: props.collection,
syncId: sync.id,
status: "SUCCEEDED",
});
console.info("Updated sync status to SUCCEEDED");
const jsonData = await response.json();
console.info(jsonData.message);
} catch (error) {
await updateSync({
collection: props.collection,
Expand Down
22 changes: 19 additions & 3 deletions packages/@runlightyear/lightyear/src/handler/handleRun.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { getActionData } from "../base/action";
import { run } from "../run";
import { handlerResult } from "./handlerResult";
import { getRunFuncProps } from "../base/run";
import { BaseRequestError } from "../base/BaseRequestError";
import { HttpProxyResponseError } from "../base/http";

export interface HandleRunProps {
actionName: string | undefined;
Expand Down Expand Up @@ -53,7 +54,22 @@ export async function handleRun({
return handlerResult(202, "Run skipped");
}

console.error("Failed to run action", String(error));
return handlerResult(500, "Run failed");
console.error("Run failed here", String(error));

if (error instanceof HttpProxyResponseError) {
console.error(error.response);
}

if (error instanceof BaseRequestError) {
const body = await error.response.text();
try {
const jsonData = JSON.parse(body);
console.error(jsonData);
} catch (e2) {
console.error(body);
}
}

return handlerResult(500, "Run failed there");
}
}
1 change: 1 addition & 0 deletions packages/@runlightyear/lightyear/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export {
upsertObjectBatch,
deleteObject,
detectHardDeletes,
finishSync,
} from "./base/collection";
export type {
DefineCollectionProps,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ export class PrefixedRedactedConsole {
}) {
const { params, color, prefix, stream, display } = props;
const message = `[${prefix}]: ${this._redactParams(params)}`;
this.history.push(message);
if (!this.streamLogsTo) {
this.history.push(message);
}
this._enqueue({
message: this._redactParams(params),
prefix,
Expand Down
10 changes: 10 additions & 0 deletions packages/@runlightyear/linear/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# @runlightyear/linear

## 0.10.14

### Patch Changes

- Updated dependencies [f723e889d]
- Updated dependencies [18e743421]
- Updated dependencies [3e7c405bd]
- Updated dependencies [86e21087b]
- @runlightyear/lightyear@1.19.0

## 0.10.13

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/@runlightyear/linear/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@runlightyear/linear",
"version": "0.10.13",
"version": "0.10.14",
"publishConfig": {
"access": "public"
},
Expand Down
10 changes: 10 additions & 0 deletions packages/@runlightyear/notion/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# @runlightyear/notion

## 1.3.13

### Patch Changes

- Updated dependencies [f723e889d]
- Updated dependencies [18e743421]
- Updated dependencies [3e7c405bd]
- Updated dependencies [86e21087b]
- @runlightyear/lightyear@1.19.0

## 1.3.12

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/@runlightyear/notion/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@runlightyear/notion",
"version": "1.3.12",
"version": "1.3.13",
"publishConfig": {
"access": "public"
},
Expand Down
Loading
Loading