From c67139b357469dacced85bcc8366e55c51ad1801 Mon Sep 17 00:00:00 2001 From: Kemal Hadimli Date: Thu, 19 Sep 2024 10:26:52 +0100 Subject: [PATCH 1/3] feat: Add `SchedulerOptions()` helper method to `plugin.SyncOptions` --- plugin/plugin_source.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/plugin/plugin_source.go b/plugin/plugin_source.go index 6bdbfc8e1b..367220fa30 100644 --- a/plugin/plugin_source.go +++ b/plugin/plugin_source.go @@ -6,6 +6,7 @@ import ( "github.com/cloudquery/plugin-sdk/v4/glob" "github.com/cloudquery/plugin-sdk/v4/message" + "github.com/cloudquery/plugin-sdk/v4/scheduler" "github.com/cloudquery/plugin-sdk/v4/schema" "github.com/rs/zerolog" ) @@ -29,6 +30,16 @@ type SyncOptions struct { Shard *Shard } +func (o SyncOptions) SchedulerOptions(additionalOpts ...scheduler.SyncOption) []scheduler.SyncOption { + opts := []scheduler.SyncOption{ + scheduler.WithSyncDeterministicCQID(o.DeterministicCQID), + } + if o.Shard != nil { + opts = append(opts, scheduler.WithShard(o.Shard.Num, o.Shard.Total)) + } + return append(opts, additionalOpts...) +} + type SourceClient interface { Close(ctx context.Context) error Tables(ctx context.Context, options TableOptions) (schema.Tables, error) From 77daaf337ce6f322faae2d997c54450d09e0e7b2 Mon Sep 17 00:00:00 2001 From: Kemal Hadimli Date: Thu, 19 Sep 2024 10:44:55 +0100 Subject: [PATCH 2/3] Rearrange --- plugin/plugin_source.go | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/plugin/plugin_source.go b/plugin/plugin_source.go index 367220fa30..6bdbfc8e1b 100644 --- a/plugin/plugin_source.go +++ b/plugin/plugin_source.go @@ -6,7 +6,6 @@ import ( "github.com/cloudquery/plugin-sdk/v4/glob" "github.com/cloudquery/plugin-sdk/v4/message" - "github.com/cloudquery/plugin-sdk/v4/scheduler" "github.com/cloudquery/plugin-sdk/v4/schema" "github.com/rs/zerolog" ) @@ -30,16 +29,6 @@ type SyncOptions struct { Shard *Shard } -func (o SyncOptions) SchedulerOptions(additionalOpts ...scheduler.SyncOption) []scheduler.SyncOption { - opts := []scheduler.SyncOption{ - scheduler.WithSyncDeterministicCQID(o.DeterministicCQID), - } - if o.Shard != nil { - opts = append(opts, scheduler.WithShard(o.Shard.Num, o.Shard.Total)) - } - return append(opts, additionalOpts...) -} - type SourceClient interface { Close(ctx context.Context) error Tables(ctx context.Context, options TableOptions) (schema.Tables, error) From 4d699f5bab90c9770e3f1e2766c39fca2b8b62b3 Mon Sep 17 00:00:00 2001 From: Kemal Hadimli Date: Thu, 19 Sep 2024 11:18:09 +0100 Subject: [PATCH 3/3] add the actual file --- helpers/opts/syncoptions.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 helpers/opts/syncoptions.go diff --git a/helpers/opts/syncoptions.go b/helpers/opts/syncoptions.go new file mode 100644 index 0000000000..0af8e0100e --- /dev/null +++ b/helpers/opts/syncoptions.go @@ -0,0 +1,17 @@ +package opts + +import ( + "github.com/cloudquery/plugin-sdk/v4/plugin" + "github.com/cloudquery/plugin-sdk/v4/scheduler" +) + +// SchedulerOpts converts plugin.SyncOptions to []scheduler.SyncOption, adding additionalOpts. +func SchedulerOpts(o plugin.SyncOptions, additionalOpts ...scheduler.SyncOption) []scheduler.SyncOption { + opts := []scheduler.SyncOption{ + scheduler.WithSyncDeterministicCQID(o.DeterministicCQID), + } + if o.Shard != nil { + opts = append(opts, scheduler.WithShard(o.Shard.Num, o.Shard.Total)) + } + return append(opts, additionalOpts...) +}