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

#347 task update feature by Update errors.go #5810

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
48 changes: 48 additions & 0 deletions flyteplugins/go/tasks/errors/errors.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package errors

import (
"fmt"
"github.com/flyteorg/flyte/flytestdlib/errors"
)

// Error codes
const (
TaskFailedWithError errors.ErrorCode = "TaskFailedWithError"
DownstreamSystemError errors.ErrorCode = "DownstreamSystemError"
Expand All @@ -20,10 +22,56 @@
BackOffError errors.ErrorCode = "BackOffError"
)

// Errorf wraps the error message with a given error code.
func Errorf(errorCode errors.ErrorCode, msgFmt string, args ...interface{}) error {
return errors.Errorf(errorCode, msgFmt, args...)
}

// Wrapf wraps an existing error with additional context and a given error code.
func Wrapf(errorCode errors.ErrorCode, err error, msgFmt string, args ...interface{}) error {
return errors.Wrapf(errorCode, err, msgFmt, args...)
}

// Task represents a task that can be updated.
type Task struct {
ID string
Status string
Meta string // Example metadata for the task
}

// UpdateTask updates the task's status and metadata, handling errors during the process.
func UpdateTask(task *Task, newStatus string, newMeta string) error {

Check warning on line 43 in flyteplugins/go/tasks/errors/errors.go

View check run for this annotation

Codecov / codecov/patch

flyteplugins/go/tasks/errors/errors.go#L43

Added line #L43 was not covered by tests
// Validate input
if task == nil {
return Errorf(BadTaskSpecification, "Task cannot be nil")

Check warning on line 46 in flyteplugins/go/tasks/errors/errors.go

View check run for this annotation

Codecov / codecov/patch

flyteplugins/go/tasks/errors/errors.go#L45-L46

Added lines #L45 - L46 were not covered by tests
}
if newStatus == "" {
return Errorf(BadTaskSpecification, "New status cannot be empty")

Check warning on line 49 in flyteplugins/go/tasks/errors/errors.go

View check run for this annotation

Codecov / codecov/patch

flyteplugins/go/tasks/errors/errors.go#L48-L49

Added lines #L48 - L49 were not covered by tests
}

// Simulate task update process
fmt.Printf("Updating task %s with new status: %s\n", task.ID, newStatus)

Check warning on line 53 in flyteplugins/go/tasks/errors/errors.go

View check run for this annotation

Codecov / codecov/patch

flyteplugins/go/tasks/errors/errors.go#L53

Added line #L53 was not covered by tests

// Simulating potential failure in metadata access
if len(newMeta) > 100 { // Assuming metadata size limit is 100 characters
return Errorf(MetadataTooLarge, "Metadata size exceeds limit for task %s", task.ID)

Check warning on line 57 in flyteplugins/go/tasks/errors/errors.go

View check run for this annotation

Codecov / codecov/patch

flyteplugins/go/tasks/errors/errors.go#L56-L57

Added lines #L56 - L57 were not covered by tests
}

// Simulate a downstream system error
if task.ID == "task-123" { // Example condition where a specific task might fail
err := fmt.Errorf("failed to communicate with downstream system")
return Wrapf(DownstreamSystemError, err, "Failed to update task %s", task.ID)

Check warning on line 63 in flyteplugins/go/tasks/errors/errors.go

View check run for this annotation

Codecov / codecov/patch

flyteplugins/go/tasks/errors/errors.go#L61-L63

Added lines #L61 - L63 were not covered by tests
}

// Simulate successful update
task.Status = newStatus
task.Meta = newMeta

Check warning on line 68 in flyteplugins/go/tasks/errors/errors.go

View check run for this annotation

Codecov / codecov/patch

flyteplugins/go/tasks/errors/errors.go#L67-L68

Added lines #L67 - L68 were not covered by tests

// Simulating a runtime failure
if task.Status == "failed" {
return Errorf(RuntimeFailure, "Task %s failed during update", task.ID)

Check warning on line 72 in flyteplugins/go/tasks/errors/errors.go

View check run for this annotation

Codecov / codecov/patch

flyteplugins/go/tasks/errors/errors.go#L71-L72

Added lines #L71 - L72 were not covered by tests
}

fmt.Printf("Task %s successfully updated.\n", task.ID)
return nil

Check warning on line 76 in flyteplugins/go/tasks/errors/errors.go

View check run for this annotation

Codecov / codecov/patch

flyteplugins/go/tasks/errors/errors.go#L75-L76

Added lines #L75 - L76 were not covered by tests
}
Loading