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

Fix: Add proper onedrive sync status to api #90

Merged
merged 3 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion apiclient/types/onedrive.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type OneDriveLinks struct {
SharedLinks []string `json:"sharedLinks,omitempty"`
ThreadID string `json:"threadID,omitempty"`
RunID string `json:"runID,omitempty"`
Status string `json:"output,omitempty"`
Status string `json:"status,omitempty"`
Error string `json:"error,omitempty"`
Folders FolderSet `json:"folders,omitempty"`
}
Expand Down
28 changes: 26 additions & 2 deletions pkg/controller/handlers/uploads/onedrive.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"path/filepath"
"time"

"github.com/acorn-io/baaah/pkg/apply"
"github.com/acorn-io/baaah/pkg/router"
Expand Down Expand Up @@ -202,11 +203,34 @@ func (u *UploadHandler) HandleUploadRun(req router.Request, resp router.Response

var run v1.Run
if err := req.Get(&run, oneDriveLinks.Namespace, oneDriveLinks.Status.RunName); apierrors.IsNotFound(err) {
// Might not be in the cache yet.
return nil
} else if err != nil || !run.Status.State.IsTerminal() {
} else if err != nil {
return err
}
if !run.Status.State.IsTerminal() {
var thread v1.Thread
if err := req.Get(&thread, oneDriveLinks.Namespace, oneDriveLinks.Status.ThreadName); apierrors.IsNotFound(err) {
// Might not be in the cache yet.
return nil
} else if err != nil {
return err
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is all duplicated below. At the very least, can we pull the getting of the thread out of this if-statement and remove the place below where we get the thread.


file, err := u.workspaceClient.OpenFile(req.Ctx, thread.Spec.WorkspaceID, ".metadata.json")
if err != nil {
return err
}
defer file.Close()

var output map[string]v1.OneDriveLinksConnectorStatus
if err = json.NewDecoder(file).Decode(&output); err != nil {
return err
}
oneDriveLinks.Status.Status = output["output"].Status
oneDriveLinks.Status.Error = output["output"].Error
resp.RetryAfter(5 * time.Second)
return nil
}

var thread v1.Thread
if err := req.Get(&thread, oneDriveLinks.Namespace, oneDriveLinks.Status.ThreadName); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/storage/apis/otto.gptscript.ai/v1/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ type OnedriveLinksStatus struct {
Conditions []metav1.Condition `json:"conditions,omitempty"`
ThreadName string `json:"threadName,omitempty"`
RunName string `json:"runName,omitempty"`
Status string `json:"output,omitempty"`
Status string `json:"status,omitempty"`
Error string `json:"error,omitempty"`
Folders types.FolderSet `json:"folders,omitempty"`
LastReSyncStarted metav1.Time `json:"lastReSyncStarted,omitempty"`
}

type OneDriveLinksConnectorStatus struct {
Status string `json:"output,omitempty"`
Status string `json:"status,omitempty"`
Error string `json:"error,omitempty"`
Files map[string]types.FileDetails `json:"files,omitempty"`
Folders types.FolderSet `json:"folders,omitempty"`
Expand Down
12 changes: 9 additions & 3 deletions pkg/storage/openapi/generated/openapi_generated.go

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