Skip to content
This repository has been archived by the owner on Mar 10, 2024. It is now read-only.

feat: sync strategy override + multi-level schedules #1882

Merged
merged 7 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
7 changes: 7 additions & 0 deletions apps/mgmt-ui/src/components/logs/SyncRunsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ export default function SyncRunsTable(props: SyncRunsTableProps) {
sortable: false,
filterable: false,
},
{
field: 'strategy',
headerName: 'Strategy',
width: 160,
sortable: false,
filterable: true,
},
{
field: 'errorMessage',
headerName: 'Error Message',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ function SyncConfigDetailsPanelImpl({ syncConfigId }: SyncConfigDetailsPanelImpl
const { entities = [], isLoading: isLoadingEntities } = useEntities();
const { entitiesWhitelistConfig, isLoading: isLoadingLekkoConfigs } = useLekkoConfigs();
const [syncPeriodSecs, setSyncPeriodSecs] = useState<number | undefined>();
const [fullSyncEveryNIncrementals, setFullSyncEveryNIncrementals] = useState<number | undefined>();
const [isSaving, setIsSaving] = useState<boolean>(false);
const [providerId, setProviderId] = useState<string | undefined>();
const [destinationId, setDestinationId] = useState<string | undefined>();
Expand All @@ -80,6 +81,7 @@ function SyncConfigDetailsPanelImpl({ syncConfigId }: SyncConfigDetailsPanelImpl
? syncConfig?.config?.defaultConfig?.periodMs / 1000
: ONE_HOUR_SECONDS
);
setFullSyncEveryNIncrementals(syncConfig?.config?.defaultConfig?.fullSyncEveryNIncrementals ?? undefined);
setAutoStartOnConnection(syncConfig?.config?.defaultConfig?.autoStartOnConnection ?? true);
setStrategy(syncConfig?.config?.defaultConfig?.strategy ?? 'full then incremental');
setCommonObjects(syncConfig?.config?.commonObjects?.map((o) => o.object) ?? []);
Expand Down Expand Up @@ -120,6 +122,7 @@ function SyncConfigDetailsPanelImpl({ syncConfigId }: SyncConfigDetailsPanelImpl
...syncConfig.config.defaultConfig,
periodMs: syncPeriodSecs ? syncPeriodSecs * 1000 : ONE_HOUR_SECONDS,
strategy,
fullSyncEveryNIncrementals: fullSyncEveryNIncrementals ?? undefined,
autoStartOnConnection,
},
commonObjects: commonObjects.map((object) => ({ object } as CommonObjectConfig)),
Expand Down Expand Up @@ -290,6 +293,26 @@ function SyncConfigDetailsPanelImpl({ syncConfigId }: SyncConfigDetailsPanelImpl
For Incremental: we will use this strategy when available for the provider and object otherwise we will
use full sync. Please refer to provider docs for more details.
</FormHelperText>
{strategy === 'full then incremental' && (
<>
<Typography variant="subtitle1">Run Full Sync every N incremental Syncs</Typography>
<TextField
value={fullSyncEveryNIncrementals}
size="small"
label="Run Full Sync every N incremental Syncs"
variant="outlined"
type="number"
helperText="All values < 1 will be taken to mean 'never'"
onChange={(event: React.ChangeEvent<HTMLInputElement>) => {
let value: number | undefined = parseInt(event.target.value, 10);
if (Number.isNaN(value) || value < 1) {
value = undefined;
}
setFullSyncEveryNIncrementals(value);
}}
/>
</>
)}
</Stack>
<Stack className="gap-2">
<SwitchWithLabel
Expand Down
42 changes: 33 additions & 9 deletions docs/docs/api/v2/mgmt/create-sync-config.api.mdx

Large diffs are not rendered by default.

22 changes: 17 additions & 5 deletions docs/docs/api/v2/mgmt/delete-sync-config.api.mdx

Large diffs are not rendered by default.

22 changes: 17 additions & 5 deletions docs/docs/api/v2/mgmt/get-sync-config.api.mdx

Large diffs are not rendered by default.

22 changes: 17 additions & 5 deletions docs/docs/api/v2/mgmt/get-sync-configs.api.mdx

Large diffs are not rendered by default.

42 changes: 33 additions & 9 deletions docs/docs/api/v2/mgmt/update-sync-config.api.mdx

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,28 +1,7 @@
type: object
properties:
default_config:
type: object
description: Configuration options for "how" to sync.
properties:
period_ms:
type: integer
minimum: 60000
example: 60000
description: The period (in milliseconds) to run the sync.
strategy:
type: string
enum:
- full then incremental
- full only
description: \"full then incremental\" will run a full sync on the first run, then incremental syncs. \"full only\" will run a full sync on every run.
auto_start_on_connection:
type: boolean
description: |
If true, the sync will start automatically when the connection is created.
Default: true
required:
- period_ms
- strategy
$ref: ./sync_strategy_config.yaml
common_objects:
description: A list of Supaglue objects to be synced.
type: array
Expand All @@ -33,6 +12,8 @@ properties:
type: string
description: The Supaglue object name
example: contact
sync_strategy_override:
$ref: ./sync_strategy_config.yaml
required:
- object
standard_objects:
Expand All @@ -45,6 +26,8 @@ properties:
type: string
description: The Provider object name (case sensitive)
example: Contact
sync_strategy_override:
$ref: ./sync_strategy_config.yaml
required:
- object
custom_objects:
Expand All @@ -57,6 +40,8 @@ properties:
type: string
description: The custom object name (case sensitive). For Salesforce, this should end with `__c`.
example: MyCustomObject__c
sync_strategy_override:
$ref: ./sync_strategy_config.yaml
required:
- object
entities:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
type: object
description: Configuration options for "how" to sync.
properties:
period_ms:
type: integer
minimum: 60000
example: 60000
description: The period (in milliseconds) to run the sync.
strategy:
type: string
enum:
- full then incremental
- full only
description: \"full then incremental\" will run a full sync on the first run, then incremental syncs. \"full only\" will run a full sync on every run.
auto_start_on_connection:
type: boolean
description: |
If true, the sync will start automatically when the connection is created.
Default: true
full_sync_every_n_incrementals:
type: number
description: If set, Supaglue will run a full sync after N consecutive incremental syncs.
required:
- period_ms
- strategy
68 changes: 42 additions & 26 deletions openapi/v2/mgmt/openapi.bundle.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions openapi/v2/mgmt/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ components:
$ref: ./components/schemas/objects/sync_config.yaml
sync_config_data:
$ref: ./components/schemas/objects/sync_config_data.yaml
sync_strategy_config:
$ref: ./components/schemas/objects/sync_strategy_config.yaml
create_provider_config:
$ref: ./components/schemas/objects/create_provider_config.yaml
update_provider_config:
Expand Down
13 changes: 9 additions & 4 deletions packages/core/mappers/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,21 @@ import { parseCustomerIdPk } from '../lib';
export const fromSyncModel = (model: SyncModel): Sync => {
// `strategy` looks like { type: 'full then incremental', ...otherProps }

const { type: strategyType, ...otherStrategyProps } = model.strategy as { type: SyncStrategyType } & Record<
string,
unknown
>;
const {
type: strategyType,
fullSyncEveryNIncrementals,
...otherStrategyProps
} = model.strategy as {
type: SyncStrategyType;
fullSyncEveryNIncrementals?: number;
} & Record<string, unknown>;

// TODO: don't do type assertion
const base = {
id: model.id,
connectionId: model.connectionId,
strategyType,
fullSyncEveryNIncrementals,
syncConfigId: model.syncConfigId,
...otherStrategyProps,
state: model.state as SyncState,
Expand Down
1 change: 1 addition & 0 deletions packages/core/mappers/sync_run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const fromSyncRunModelAndSync = (args: SyncRunModelExpanded): SyncRun =>
id,
syncId: sync.id,
status: status as SyncRunStatus,
strategy: args.strategy as 'full' | 'incremental',
errorMessage,
startTimestamp,
endTimestamp,
Expand Down
Loading