@@ -13,6 +13,7 @@ import (
1313 "github.com/render-oss/cli/pkg/tasks"
1414 "github.com/render-oss/cli/pkg/version"
1515 "github.com/render-oss/cli/pkg/workflow"
16+ "github.com/render-oss/cli/pkg/workflowversion"
1617)
1718
1819type WorkflowLoaderDeps interface {
@@ -116,46 +117,54 @@ func (w *WorkflowLoader) ReleaseVersion(ctx context.Context, input VersionReleas
116117
117118func (w * WorkflowLoader ) WaitForVersion (ctx context.Context , workflowID , workflowVersionID string ) (* wfclient.WorkflowVersion , error ) {
118119 timeoutTimer := time .NewTimer (versionTimeout )
120+ ticker := time .NewTicker (5 * time .Second )
121+ defer ticker .Stop ()
122+
123+ // Check immediately before waiting for the first tick
124+ v , err := w .workflowVersionRepo .GetVersion (ctx , workflowVersionID )
125+ if err != nil {
126+ return nil , err
127+ }
128+ if workflowversion .IsComplete (v .Status ) {
129+ return v , nil
130+ }
119131
120132 for {
121133 select {
122134 case <- timeoutTimer .C :
123135 return nil , fmt .Errorf ("timed out waiting for release to finish" )
124- default :
136+ case <- ticker . C :
125137 v , err := w .workflowVersionRepo .GetVersion (ctx , workflowVersionID )
126138 if err != nil {
127139 return nil , err
128140 }
129141
130- return v , nil
131-
132- // TODO CAP-7490
133- // https://linear.app/render-com/issue/CAP-7490/flesh-out-workflow-version-information-at-least-restgql-if-not-present
134- // if workflowversion.IsComplete(v.Status) {
135- // return v, nil
136- // }
137-
138- // if v.Status == nil || *v.Status == client.VersionStatusCreated {
139- // time.Sleep(10 * time.Second)
140- // } else {
141- // // if the release has started, poll more frequently
142- // time.Sleep(5 * time.Second)
143- // }
142+ if workflowversion .IsComplete (v .Status ) {
143+ return v , nil
144+ }
144145 }
145146 }
146147}
147148
148149func (w * WorkflowLoader ) WaitForVersionRelease (ctx context.Context , workflowID string ) (* wfclient.WorkflowVersion , error ) {
149150 timeoutTimer := time .NewTimer (versionReleaseTimeout )
151+ ticker := time .NewTicker (time .Second )
152+ defer ticker .Stop ()
153+
154+ // Check immediately before waiting for the first tick
155+ _ , wfv , err := w .workflowVersionRepo .ListVersions (ctx , workflowID , & client.ListWorkflowVersionsParams {Limit : pointers .From (1 )})
156+ if err != nil {
157+ return nil , err
158+ }
159+ if len (wfv ) > 0 {
160+ return wfv [0 ], nil
161+ }
150162
151163 for {
152164 select {
153165 case <- timeoutTimer .C :
154166 return nil , fmt .Errorf ("timed out waiting for version to be created" )
155- default :
156- // TODO CAP-7490
157- // https://linear.app/render-com/issue/CAP-7490/flesh-out-workflow-version-information-at-least-restgql-if-not-present
158- // hacky "get latest version" straight up does not work without statuses/visibility
167+ case <- ticker .C :
159168 _ , wfv , err := w .workflowVersionRepo .ListVersions (ctx , workflowID , & client.ListWorkflowVersionsParams {Limit : pointers .From (1 )})
160169 if err != nil {
161170 return nil , err
@@ -164,8 +173,6 @@ func (w *WorkflowLoader) WaitForVersionRelease(ctx context.Context, workflowID s
164173 if len (wfv ) > 0 {
165174 return wfv [0 ], nil
166175 }
167-
168- time .Sleep (time .Second )
169176 }
170177 }
171178}
0 commit comments