diff --git a/golemhost/component.go b/golemhost/component.go index 33d5e62..09cb07e 100644 --- a/golemhost/component.go +++ b/golemhost/component.go @@ -8,12 +8,12 @@ import ( type ComponentID uuid.UUID -func newComponentID(componentID binding.GolemApi0_2_0_HostComponentId) ComponentID { - return ComponentID(newUUID(componentID.Uuid)) +func NewComponentID(componentID binding.GolemApi0_2_0_HostComponentId) ComponentID { + return ComponentID(NewUUID(componentID.Uuid)) } -func (componentID ComponentID) toBinding() binding.GolemApi0_2_0_HostComponentId { +func (componentID ComponentID) ToBinding() binding.GolemApi0_2_0_HostComponentId { return binding.GolemApi0_2_0_HostComponentId{ - Uuid: uuidToBinding(uuid.UUID(componentID)), + Uuid: UUIDToBinding(uuid.UUID(componentID)), } } diff --git a/golemhost/filter.go b/golemhost/filter.go new file mode 100644 index 0000000..edb0079 --- /dev/null +++ b/golemhost/filter.go @@ -0,0 +1,177 @@ +package golemhost + +import ( + "fmt" + "time" + + "github.com/golemcloud/golem-go/binding" +) + +type FilterComparator int + +const ( + FilterComparatorEqual FilterComparator = iota + FilterComparatorNotEqual + FilterComparatorGreaterEqual + FilterComparatorGreater + FilterComparatorLessEqual + FilterComparatorLess +) + +func (filterComparator FilterComparator) ToBinding() binding.GolemApi0_2_0_HostFilterComparator { + switch filterComparator { + case FilterComparatorEqual: + return binding.GolemApi0_2_0_HostFilterComparatorEqual() + case FilterComparatorNotEqual: + return binding.GolemApi0_2_0_HostFilterComparatorNotEqual() + case FilterComparatorGreaterEqual: + return binding.GolemApi0_2_0_HostFilterComparatorGreaterEqual() + case FilterComparatorGreater: + return binding.GolemApi0_2_0_HostFilterComparatorGreater() + case FilterComparatorLessEqual: + return binding.GolemApi0_2_0_HostFilterComparatorLessEqual() + case FilterComparatorLess: + return binding.GolemApi0_2_0_HostFilterComparatorLess() + default: + panic(fmt.Sprintf("ToBinding: unhandled filterComparator: %d", filterComparator)) + } +} + +type StringFilterComparator int + +const ( + StringFilterComparatorEqual StringFilterComparator = iota + StringFilterComparatorNotEqual + StringFilterComparatorLike + StringFilterComparatorNotLike +) + +func (stringFilterComparator StringFilterComparator) ToBinding() binding.GolemApi0_2_0_HostStringFilterComparator { + switch stringFilterComparator { + case StringFilterComparatorEqual: + return binding.GolemApi0_2_0_HostStringFilterComparatorEqual() + case StringFilterComparatorNotEqual: + return binding.GolemApi0_2_0_HostStringFilterComparatorNotEqual() + case StringFilterComparatorLike: + return binding.GolemApi0_2_0_HostStringFilterComparatorLike() + case StringFilterComparatorNotLike: + return binding.GolemApi0_2_0_HostStringFilterComparatorNotLike() + default: + panic(fmt.Sprintf("ToBinding: unhandled stringFilterComparator: %d", stringFilterComparator)) + } +} + +type WorkerAnyFilter struct { + Filters []WorkerAllFilter +} + +func (f WorkerAnyFilter) ToBinding() binding.GolemApi0_2_0_HostWorkerAnyFilter { + filter := binding.GolemApi0_2_0_HostWorkerAnyFilter{ + Filters: make([]binding.GolemApi0_2_0_HostWorkerAllFilter, len(f.Filters)), + } + for i := range f.Filters { + filter.Filters[i] = f.Filters[i].ToBinding() + } + return filter +} + +type WorkerAllFilter struct { + Filters []WorkerFilter +} + +func (f WorkerAllFilter) ToBinding() binding.GolemApi0_2_0_HostWorkerAllFilter { + filter := binding.GolemApi0_2_0_HostWorkerAllFilter{} + for i := range f.Filters { + filter.Filters = append(filter.Filters, f.Filters[i].ToBinding()...) + } + return filter +} + +type WorkerEnvFilter struct { + Name string + Value string +} + +type WorkerFilter struct { + Name *string + NameComparator StringFilterComparator + + Status *WorkerStatus + StatusComparator FilterComparator + + Version *uint64 + VersionComparator FilterComparator + + CreatedAt *time.Time + CreatedAtComparator FilterComparator + + Env *WorkerEnvFilter + EnvComparator StringFilterComparator +} + +func (f WorkerFilter) ToBinding() []binding.GolemApi0_2_0_HostWorkerPropertyFilter { + var filter []binding.GolemApi0_2_0_HostWorkerPropertyFilter + + if f.Name != nil { + filter = append( + filter, + binding.GolemApi0_2_0_HostWorkerPropertyFilterName( + binding.GolemApi0_2_0_HostWorkerNameFilter{ + Comparator: f.NameComparator.ToBinding(), + Value: *f.Name, + }, + ), + ) + } + + if f.Status != nil { + filter = append( + filter, + binding.GolemApi0_2_0_HostWorkerPropertyFilterStatus( + binding.GolemApi0_2_0_HostWorkerStatusFilter{ + Comparator: f.StatusComparator.ToBinding(), + Value: f.Status.ToBinding(), + }, + ), + ) + } + + if f.Version != nil { + filter = append( + filter, + binding.GolemApi0_2_0_HostWorkerPropertyFilterVersion( + binding.GolemApi0_2_0_HostWorkerVersionFilter{ + Comparator: f.VersionComparator.ToBinding(), + Value: *f.Version, + }, + ), + ) + } + + if f.CreatedAt != nil { + filter = append( + filter, + binding.GolemApi0_2_0_HostWorkerPropertyFilterCreatedAt( + binding.GolemApi0_2_0_HostWorkerCreatedAtFilter{ + Comparator: f.CreatedAtComparator.ToBinding(), + Value: uint64(f.CreatedAt.UnixNano()), + }, + ), + ) + } + + if f.Env != nil { + filter = append( + filter, + binding.GolemApi0_2_0_HostWorkerPropertyFilterEnv( + binding.GolemApi0_2_0_HostWorkerEnvFilter{ + Comparator: f.EnvComparator.ToBinding(), + Name: f.Env.Name, + Value: f.Env.Value, + }, + ), + ) + } + + return filter +} diff --git a/golemhost/persistence.go b/golemhost/persistence.go index bf38847..fac8d74 100644 --- a/golemhost/persistence.go +++ b/golemhost/persistence.go @@ -14,7 +14,7 @@ const ( PersistenceLevelSmart ) -func newPersistenceLevel(level binding.GolemApi0_2_0_HostPersistenceLevel) PersistenceLevel { +func NewPersistenceLevel(level binding.GolemApi0_2_0_HostPersistenceLevel) PersistenceLevel { switch level.Kind() { case binding.GolemApi0_2_0_HostPersistenceLevelKindPersistRemoteSideEffects: return PersistenceLevelPersistRemoteSideEffects @@ -23,11 +23,11 @@ func newPersistenceLevel(level binding.GolemApi0_2_0_HostPersistenceLevel) Persi case binding.GolemApi0_2_0_HostPersistenceLevelKindSmart: return PersistenceLevelSmart default: - panic(fmt.Sprintf("newPersistenceLevel: unhandled persistence level: %d", level)) + panic(fmt.Sprintf("NewPersistenceLevel: unhandled persistence level: %d", level)) } } -func (level PersistenceLevel) toBinding() binding.GolemApi0_2_0_HostPersistenceLevel { +func (level PersistenceLevel) ToBinding() binding.GolemApi0_2_0_HostPersistenceLevel { switch level { case PersistenceLevelPersistNothing: return binding.GolemApi0_2_0_HostPersistenceLevelPersistNothing() @@ -36,16 +36,16 @@ func (level PersistenceLevel) toBinding() binding.GolemApi0_2_0_HostPersistenceL case PersistenceLevelSmart: return binding.GolemApi0_2_0_HostPersistenceLevelSmart() default: - panic(fmt.Sprintf("toBinding: unhandled persistence level: %d", level)) + panic(fmt.Sprintf("ToBinding: unhandled persistence level: %d", level)) } } func SetPersistenceLevel(level PersistenceLevel) { - binding.GolemApi0_2_0_HostSetOplogPersistenceLevel(level.toBinding()) + binding.GolemApi0_2_0_HostSetOplogPersistenceLevel(level.ToBinding()) } func GetPersistenceLevel() PersistenceLevel { - return newPersistenceLevel(binding.GolemApi0_2_0_HostGetOplogPersistenceLevel()) + return NewPersistenceLevel(binding.GolemApi0_2_0_HostGetOplogPersistenceLevel()) } func WithPersistenceLevel[T any](level PersistenceLevel, f func() (T, error)) (T, error) { diff --git a/golemhost/promise.go b/golemhost/promise.go index 4bb086c..12fef66 100644 --- a/golemhost/promise.go +++ b/golemhost/promise.go @@ -14,24 +14,24 @@ type PromiseID struct { func NewPromise() PromiseID { promise := binding.GolemApi0_2_0_HostCreatePromise() return PromiseID{ - WorkerID: newWorkerID(promise.WorkerId), + WorkerID: NewWorkerID(promise.WorkerId), OplogIdx: OpLogIndex(promise.OplogIdx), } } -func (promiseID PromiseID) toBinding() binding.GolemApi0_2_0_HostPromiseId { +func (promiseID PromiseID) ToBinding() binding.GolemApi0_2_0_HostPromiseId { return binding.GolemApi0_2_0_HostPromiseId{ - WorkerId: promiseID.WorkerID.toBinding(), + WorkerId: promiseID.WorkerID.ToBinding(), OplogIdx: binding.GolemApi0_2_0_HostOplogIndex(promiseID.OplogIdx), } } func DeletePromise(promiseID PromiseID) { - binding.GolemApi0_2_0_HostDeletePromise(promiseID.toBinding()) + binding.GolemApi0_2_0_HostDeletePromise(promiseID.ToBinding()) } func AwaitPromise(promiseID PromiseID) []byte { - return binding.GolemApi0_2_0_HostAwaitPromise(promiseID.toBinding()) + return binding.GolemApi0_2_0_HostAwaitPromise(promiseID.ToBinding()) } func AwaitPromiseJSON(promiseID PromiseID, v any) error { @@ -39,7 +39,7 @@ func AwaitPromiseJSON(promiseID PromiseID, v any) error { } func CompletePromise(promiseID PromiseID, payload []byte) bool { - return binding.GolemApi0_2_0_HostCompletePromise(promiseID.toBinding(), payload) + return binding.GolemApi0_2_0_HostCompletePromise(promiseID.ToBinding(), payload) } func CompletePromiseJSON(promiseID PromiseID, v any) (bool, error) { diff --git a/golemhost/retrypolicy.go b/golemhost/retrypolicy.go index d29d075..9877039 100644 --- a/golemhost/retrypolicy.go +++ b/golemhost/retrypolicy.go @@ -13,7 +13,7 @@ type RetryPolicy struct { Multiplier float64 } -func newRetryPolicy(policy binding.GolemApi0_2_0_HostRetryPolicy) RetryPolicy { +func NewRetryPolicy(policy binding.GolemApi0_2_0_HostRetryPolicy) RetryPolicy { return RetryPolicy{ MaxAttempts: policy.MaxAttempts, MinDelay: time.Duration(policy.MinDelay) * time.Nanosecond, @@ -22,7 +22,7 @@ func newRetryPolicy(policy binding.GolemApi0_2_0_HostRetryPolicy) RetryPolicy { } } -func (policy RetryPolicy) toBinding() binding.GolemApi0_2_0_HostRetryPolicy { +func (policy RetryPolicy) ToBinding() binding.GolemApi0_2_0_HostRetryPolicy { return binding.GolemApi0_2_0_HostRetryPolicy{ MaxAttempts: policy.MaxAttempts, MinDelay: binding.GolemApi0_2_0_HostDuration(policy.MinDelay.Nanoseconds()), @@ -32,11 +32,11 @@ func (policy RetryPolicy) toBinding() binding.GolemApi0_2_0_HostRetryPolicy { } func GetRetryPolicy() RetryPolicy { - return newRetryPolicy(binding.GolemApi0_2_0_HostGetRetryPolicy()) + return NewRetryPolicy(binding.GolemApi0_2_0_HostGetRetryPolicy()) } func SetRetryPolicy(policy RetryPolicy) { - binding.GolemApi0_2_0_HostSetRetryPolicy(policy.toBinding()) + binding.GolemApi0_2_0_HostSetRetryPolicy(policy.ToBinding()) } func WithRetryPolicy[T any](policy RetryPolicy, f func() (T, error)) (T, error) { diff --git a/golemhost/transaction/errors.go b/golemhost/transaction/errors.go index fa8c17b..1c7643f 100644 --- a/golemhost/transaction/errors.go +++ b/golemhost/transaction/errors.go @@ -3,55 +3,55 @@ package transaction import "fmt" type FailedAndRolledBackPartiallyError struct { - StepIndex uint - StepError error + ExecuteIndex uint + ExecuteError error CompensationIndex uint CompensationError error } func (e *FailedAndRolledBackPartiallyError) Error() string { return fmt.Sprintf( - "fallible transaction failed and rolled back partially, step (%d) error: %s, compensation (%d) error: %s", - e.StepIndex, - e.StepError.Error(), + "fallible transaction failed and rolled back partially, execute (%d) error: %s, compensation (%d) error: %s", + e.ExecuteIndex, + e.ExecuteError.Error(), e.CompensationIndex, e.CompensationError.Error(), ) } func (e *FailedAndRolledBackPartiallyError) Unwrap() []error { - return []error{e.StepError, e.CompensationError} + return []error{e.ExecuteError, e.CompensationError} } type FailedAndRolledBackCompletelyError struct { - StepIndex uint - StepError error + ExecuteIndex uint + ExecuteError error } func (e *FailedAndRolledBackCompletelyError) Error() string { return fmt.Sprintf( - "fallible transaction failed and rolled back completely, step (%d) error: %s", - e.StepIndex, - e.StepError.Error(), + "fallible transaction failed and rolled back completely, execute (%d) error: %s", + e.ExecuteIndex, + e.ExecuteError.Error(), ) } func (e *FailedAndRolledBackCompletelyError) Unwrap() error { - return e.StepError + return e.ExecuteError } -type CannotExecuteStepInFailedTransactionError struct { +type CannotExecuteInFailedTransactionError struct { OriginalError error } -func (e *CannotExecuteStepInFailedTransactionError) Error() string { +func (e *CannotExecuteInFailedTransactionError) Error() string { return fmt.Sprintf( - "cannot execute step in failed transaction, original error: %s", + "cannot execute in failed transaction, original error: %s", e.OriginalError.Error(), ) } -func (e *CannotExecuteStepInFailedTransactionError) Unwrap() error { +func (e *CannotExecuteInFailedTransactionError) Unwrap() error { return e.OriginalError } diff --git a/golemhost/transaction/fallible.go b/golemhost/transaction/fallible.go index c93b89e..d26ce7c 100644 --- a/golemhost/transaction/fallible.go +++ b/golemhost/transaction/fallible.go @@ -22,20 +22,20 @@ func (tx *fallible) addCompensationStep(compensationStep func() error) { func (tx *fallible) fail(err error) error { tx.err = err stepsCount := len(tx.compensations) - for i := stepsCount - 0; i >= 0; i-- { + for i := stepsCount - 1; i >= 0; i-- { err := tx.compensations[i]() if err != nil { return &FailedAndRolledBackPartiallyError{ - StepIndex: tx.stepIndex, - StepError: tx.err, + ExecuteIndex: tx.stepIndex, + ExecuteError: tx.err, CompensationIndex: uint(i), CompensationError: err, } } } return &FailedAndRolledBackCompletelyError{ - StepIndex: tx.stepIndex, - StepError: tx.error(), + ExecuteIndex: tx.stepIndex, + ExecuteError: tx.error(), } } @@ -54,7 +54,7 @@ func (tx *fallible) finish() { func ExecuteFallible[I, O any](tx FallibleTx, op Operation[I, O], input I) (O, error) { if tx.isFailed() { - return *new(O), &CannotExecuteStepInFailedTransactionError{OriginalError: tx.error()} + return *new(O), &CannotExecuteInFailedTransactionError{OriginalError: tx.error()} } output, err := op.Execute(input) diff --git a/golemhost/transaction/infallible.go b/golemhost/transaction/infallible.go index 026ef97..a19aa1c 100644 --- a/golemhost/transaction/infallible.go +++ b/golemhost/transaction/infallible.go @@ -35,12 +35,12 @@ func (tx *infallible) addCompensationStep(compensationStep func() error) { func (tx *infallible) retry(err error) { tx.err = err stepsCount := len(tx.compensationSteps) - for i := stepsCount - 0; i >= 0; i-- { + for i := stepsCount - 1; i >= 0; i-- { err := tx.compensationSteps[i]() if err != nil { err := &FailedAndRolledBackPartiallyError{ - StepIndex: tx.stepIndex, - StepError: tx.err, + ExecuteIndex: tx.stepIndex, + ExecuteError: tx.err, CompensationIndex: uint(i), CompensationError: err, } diff --git a/golemhost/uuid.go b/golemhost/uuid.go index 34b3df4..58c5128 100644 --- a/golemhost/uuid.go +++ b/golemhost/uuid.go @@ -9,19 +9,19 @@ import ( "github.com/golemcloud/golem-go/binding" ) -func newUUID(bindingUUID binding.GolemApi0_2_0_HostUuid) uuid.UUID { +func NewUUID(bindingUUID binding.GolemApi0_2_0_HostUuid) uuid.UUID { var bs [16]byte binary.BigEndian.PutUint64(bs[:8], bindingUUID.HighBits) binary.BigEndian.PutUint64(bs[8:], bindingUUID.LowBits) goUUID, err := uuid.FromBytes(bs[:]) if err != nil { - panic(fmt.Sprintf("newUUID: uuid.FromBytes failed: error: %s,bytes: %+v", err.Error(), bs)) + panic(fmt.Sprintf("NewUUID: uuid.FromBytes failed: error: %s,bytes: %+v", err.Error(), bs)) } return goUUID } -func uuidToBinding(goUUID uuid.UUID) binding.GolemApi0_2_0_HostUuid { +func UUIDToBinding(goUUID uuid.UUID) binding.GolemApi0_2_0_HostUuid { return binding.GolemApi0_2_0_HostUuid{ HighBits: binary.BigEndian.Uint64(goUUID[:8]), LowBits: binary.BigEndian.Uint64(goUUID[8:]), diff --git a/golemhost/worker.go b/golemhost/worker.go index 222b263..f61d90b 100644 --- a/golemhost/worker.go +++ b/golemhost/worker.go @@ -2,6 +2,9 @@ package golemhost import ( "fmt" + + "github.com/google/uuid" + "github.com/golemcloud/golem-go/binding" ) @@ -17,7 +20,7 @@ const ( WorkerStatusExited ) -func newWorkerStatus(status binding.GolemApi0_2_0_HostWorkerStatus) WorkerStatus { +func NewWorkerStatus(status binding.GolemApi0_2_0_HostWorkerStatus) WorkerStatus { switch status.Kind() { case binding.GolemApi0_2_0_HostWorkerStatusKindRunning: return WorkerStatusRunning @@ -34,11 +37,11 @@ func newWorkerStatus(status binding.GolemApi0_2_0_HostWorkerStatus) WorkerStatus case binding.GolemApi0_2_0_HostWorkerStatusKindExited: return WorkerStatusExited default: - panic(fmt.Sprintf("newWorkerStatus: unhandled status: %d", status.Kind())) + panic(fmt.Sprintf("NewWorkerStatus: unhandled status: %d", status.Kind())) } } -func (ws WorkerStatus) toBinding() binding.GolemApi0_2_0_HostWorkerStatus { +func (ws WorkerStatus) ToBinding() binding.GolemApi0_2_0_HostWorkerStatus { switch ws { case WorkerStatusRunning: return binding.GolemApi0_2_0_HostWorkerStatusRunning() @@ -55,7 +58,7 @@ func (ws WorkerStatus) toBinding() binding.GolemApi0_2_0_HostWorkerStatus { case WorkerStatusExited: return binding.GolemApi0_2_0_HostWorkerStatusExited() default: - panic(fmt.Sprintf("toBinding: unhandled status: %d", ws)) + panic(fmt.Sprintf("ToBinding: unhandled status: %d", ws)) } } @@ -64,16 +67,16 @@ type WorkerID struct { WorkerName string } -func newWorkerID(workerID binding.GolemApi0_2_0_HostWorkerId) WorkerID { +func NewWorkerID(workerID binding.GolemApi0_2_0_HostWorkerId) WorkerID { return WorkerID{ - ComponentID: newComponentID(workerID.ComponentId), + ComponentID: NewComponentID(workerID.ComponentId), WorkerName: workerID.WorkerName, } } -func (workerID WorkerID) toBinding() binding.GolemApi0_2_0_HostWorkerId { +func (workerID WorkerID) ToBinding() binding.GolemApi0_2_0_HostWorkerId { return binding.GolemApi0_2_0_HostWorkerId{ - ComponentId: workerID.ComponentID.toBinding(), + ComponentId: workerID.ComponentID.ToBinding(), WorkerName: workerID.WorkerName, } } @@ -92,7 +95,7 @@ type WorkerMetadata struct { RetryCount uint64 } -func newWorkerMetadata(metadata binding.GolemApi0_2_0_HostWorkerMetadata) WorkerMetadata { +func NewWorkerMetadata(metadata binding.GolemApi0_2_0_HostWorkerMetadata) WorkerMetadata { envVars := make([]WorkerMetadataEnvVar, len(metadata.Env)) for i := range metadata.Env { envVars[i] = WorkerMetadataEnvVar{ @@ -102,24 +105,79 @@ func newWorkerMetadata(metadata binding.GolemApi0_2_0_HostWorkerMetadata) Worker } return WorkerMetadata{ - WorkerId: newWorkerID(metadata.WorkerId), + WorkerId: NewWorkerID(metadata.WorkerId), Args: metadata.Args, Env: envVars, - Status: newWorkerStatus(metadata.Status), + Status: NewWorkerStatus(metadata.Status), ComponentVersion: metadata.ComponentVersion, RetryCount: metadata.RetryCount, } } func GetSelfMetadata() WorkerMetadata { - return newWorkerMetadata(binding.GolemApi0_2_0_HostGetSelfMetadata()) + return NewWorkerMetadata(binding.GolemApi0_2_0_HostGetSelfMetadata()) +} + +func GetSelfURI(functionName string) string { + return binding.GolemApi0_2_0_HostGetSelfUri(functionName).Value } func GetWorkerMetadata(workerID WorkerID) *WorkerMetadata { - bindingMetadata := binding.GolemApi0_2_0_HostGetWorkerMetadata(workerID.toBinding()) + bindingMetadata := binding.GolemApi0_2_0_HostGetWorkerMetadata(workerID.ToBinding()) if bindingMetadata.IsNone() { return nil } - metadata := newWorkerMetadata(bindingMetadata.Unwrap()) + metadata := NewWorkerMetadata(bindingMetadata.Unwrap()) return &metadata } + +// GetWorkers enumerates all the workers optionally matching the provided filter +// NOTE: Enumerating workers of a component is a slow operation and should not be used as part of the application logic. +func GetWorkers(componentID ComponentID, filter *WorkerAnyFilter) []WorkerMetadata { + bindingFilter := binding.None[binding.GolemApi0_2_0_HostWorkerAnyFilter]() + if filter == nil { + bindingFilter.Set(filter.ToBinding()) + } + + iter := binding.NewGetWorkers(componentID.ToBinding(), bindingFilter, true) + + var results []WorkerMetadata + for { + nextResults := iter.GetNext() + if nextResults.IsNone() { + break + } + + for _, metadata := range nextResults.Unwrap() { + results = append(results, NewWorkerMetadata(metadata)) + } + } + + return results +} + +type UpdateMode int + +const ( + UpdateModeAutomatic UpdateMode = iota + UpdateModeSnapshotBased +) + +func (updateMode UpdateMode) ToBinding() binding.GolemApi0_2_0_HostUpdateMode { + switch updateMode { + case UpdateModeAutomatic: + return binding.GolemApi0_2_0_HostUpdateModeAutomatic() + case UpdateModeSnapshotBased: + return binding.GolemApi0_2_0_HostUpdateModeSnapshotBased() + default: + panic(fmt.Sprintf("ToBinding: unhandled update mode: %d", updateMode)) + } +} + +func UpdateWorker(workerID WorkerID, targetVersion uint64, updateMode UpdateMode) { + binding.GolemApi0_2_0_HostUpdateWorker(workerID.ToBinding(), targetVersion, updateMode.ToBinding()) +} + +func GenerateIdempotencyKey() uuid.UUID { + return NewUUID(binding.GolemApi0_2_0_HostGenerateIdempotencyKey()) +} diff --git a/ptr/ptr.go b/ptr/ptr.go new file mode 100644 index 0000000..8bcf9cc --- /dev/null +++ b/ptr/ptr.go @@ -0,0 +1,4 @@ +package ptr + +// New is a helper for creating pointers inline +func New[T any](t T) *T { return &t } diff --git a/test_app/main.go b/test_app/main.go index d6c29a7..6474efc 100644 --- a/test_app/main.go +++ b/test_app/main.go @@ -11,6 +11,7 @@ import ( "github.com/golemcloud/golem-go/golemhost/transaction" "github.com/golemcloud/golem-go/net/http" "github.com/golemcloud/golem-go/os" + "github.com/golemcloud/golem-go/ptr" "github.com/golemcloud/golem-go/std" ) @@ -201,6 +202,68 @@ func main() { unused(metadata) } + { + var results []golemhost.WorkerMetadata + results = golemhost.GetWorkers( + golemhost.ComponentID(uuid.New()), + &golemhost.WorkerAnyFilter{ + Filters: []golemhost.WorkerAllFilter{ + { + Filters: []golemhost.WorkerFilter{ + { + Name: ptr.New("worker name"), + NameComparator: golemhost.StringFilterComparatorLike, + }, + { + CreatedAt: ptr.New(time.Now()), + CreatedAtComparator: golemhost.FilterComparatorLessEqual, + }, + { + Version: ptr.New[uint64](10), + VersionComparator: golemhost.FilterComparatorNotEqual, + }, + { + Status: ptr.New[golemhost.WorkerStatus](golemhost.WorkerStatusFailed), + StatusComparator: golemhost.FilterComparatorEqual, + }, + { + Env: &golemhost.WorkerEnvFilter{ + Name: "ENV_VAR", + Value: "ENV_VAR_VALUE", + }, + EnvComparator: golemhost.StringFilterComparatorEqual, + }, + }, + }, + }, + }, + ) + unused(results) + } + + { + golemhost.UpdateWorker( + golemhost.WorkerID{ + ComponentID: golemhost.ComponentID(uuid.New()), + WorkerName: "worker-name", + }, + 20, + golemhost.UpdateModeAutomatic, + ) + } + + { + var result string + result = golemhost.GetSelfURI("get") + unused(result) + } + + { + var result uuid.UUID + result = golemhost.GenerateIdempotencyKey() + unused(result) + } + // golemhost/transaction - fallible { var result Result