@@ -121,14 +121,14 @@ func (i *DeploymentInteractor) Deploy(ctx context.Context, u *ent.User, r *ent.R
121121 i .log .Error ("Failed to request a review." , zap .Errors ("errs" , errs ))
122122 }
123123
124- i .log .Debug ("Dispatch a event." )
125- if _ , err := i .store .CreateEvent (ctx , & ent.Event {
126- Kind : event .KindDeployment ,
127- Type : event .TypeCreated ,
124+ if _ , err := i .CreateDeploymentStatus (ctx , & ent.DeploymentStatus {
125+ Status : string (deployment .StatusWaiting ),
126+ Description : "Gitploy waits the reviews." ,
128127 DeploymentID : d .ID ,
129128 }); err != nil {
130- i .log .Error ("Failed to create the event ." , zap .Error (err ))
129+ i .log .Error ("Failed to create a deployment status ." , zap .Error (err ))
131130 }
131+
132132 return d , nil
133133 }
134134
@@ -149,20 +149,14 @@ func (i *DeploymentInteractor) Deploy(ctx context.Context, u *ent.User, r *ent.R
149149 return nil , fmt .Errorf ("It failed to save a new deployment.: %w" , err )
150150 }
151151
152- i . store .CreateDeploymentStatus (ctx , & ent.DeploymentStatus {
152+ if _ , err := i .CreateDeploymentStatus (ctx , & ent.DeploymentStatus {
153153 Status : string (deployment .StatusCreated ),
154154 Description : "Gitploy starts to deploy." ,
155155 DeploymentID : d .ID ,
156- })
157-
158- i .log .Debug ("Dispatch a event." )
159- if _ , err := i .store .CreateEvent (ctx , & ent.Event {
160- Kind : event .KindDeployment ,
161- Type : event .TypeCreated ,
162- DeploymentID : d .ID ,
163156 }); err != nil {
164- i .log .Error ("Failed to create the event ." , zap .Error (err ))
157+ i .log .Error ("Failed to create a deployment status ." , zap .Error (err ))
165158 }
159+
166160 return d , nil
167161}
168162
@@ -237,9 +231,9 @@ func (i *DeploymentInteractor) DeployToRemote(ctx context.Context, u *ent.User,
237231 return nil , err
238232 }
239233
240- i .store . CreateDeploymentStatus (ctx , & ent.DeploymentStatus {
234+ i .CreateDeploymentStatus (ctx , & ent.DeploymentStatus {
241235 Status : string (deployment .StatusCreated ),
242- Description : "Gitploy creates a new deployment ." ,
236+ Description : "Gitploy start to deploy ." ,
243237 DeploymentID : d .ID ,
244238 })
245239
@@ -258,6 +252,24 @@ func (i *DeploymentInteractor) createRemoteDeployment(ctx context.Context, u *en
258252 return i .scm .CreateRemoteDeployment (ctx , u , r , d , env )
259253}
260254
255+ // CreateDeploymentStatus create a DeploymentStatus and dispatch the event.
256+ func (i * DeploymentInteractor ) CreateDeploymentStatus (ctx context.Context , ds * ent.DeploymentStatus ) (* ent.DeploymentStatus , error ) {
257+ ds , err := i .store .CreateEntDeploymentStatus (ctx , ds )
258+ if err != nil {
259+ return nil , err
260+ }
261+
262+ if _ , err := i .store .CreateEvent (ctx , & ent.Event {
263+ Kind : event .KindDeploymentStatus ,
264+ Type : event .TypeCreated ,
265+ DeploymentStatusID : ds .ID ,
266+ }); err != nil {
267+ i .log .Error ("Failed to dispatch the event." , zap .Error (err ))
268+ }
269+
270+ return ds , nil
271+ }
272+
261273func (i * DeploymentInteractor ) runClosingInactiveDeployment (stop <- chan struct {}) {
262274 ctx := context .Background ()
263275
295307 continue
296308 }
297309
298- if _ , err := i .store . CreateDeploymentStatus (ctx , s ); err != nil {
310+ if _ , err := i .CreateDeploymentStatus (ctx , s ); err != nil {
299311 i .log .Error ("It has failed to create a new deployment status." , zap .Error (err ))
300312 continue
301313 }
0 commit comments