-
Notifications
You must be signed in to change notification settings - Fork 550
feat: optimize ci cd workflow #6744
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
87521d5
Add workflow status latest service with CI/CD status optimization
prakash100198 b97e7e4
Decouple workflow status management by deriving `status` from respect…
prakash100198 bc7e274
Refactor `WorkflowStatusLatestService` to derive `status` from workfl…
prakash100198 604baa8
Remove `WorkflowStatusLatestService` usage and fallback logic from `C…
prakash100198 17c1dae
Refactor workflow status handling: rename `WorkflowStatusLatestServic…
prakash100198 cb6ce49
Integrate optimized CI workflow fetching in `CiHandlerImpl` using `Fi…
prakash100198 96815d3
Add `StorageConfigured` field to `CiWorkflowStatusLatest` and update …
prakash100198 4a0bc3a
wip: adding code for cd
iamayushm fc4c6aa
Implement hybrid CI workflow status fetching in `CiHandlerImpl` using…
prakash100198 7f327f2
wip
iamayushm 19f6886
Rename `GetCachedPipelineIds` to `GetByPipelineIds` in `WorkflowStatu…
prakash100198 01b8bc6
Refactor CI status fetching in `CiHandlerImpl` by renaming methods fo…
prakash100198 3bc8e3d
Refactor method names and variable references in `CiHandlerImpl` for …
prakash100198 02fd2b4
Remove unused `GetByPipelineIds` method from `WorkflowStatusLatestRep…
prakash100198 b3e96fc
Refactor `WorkflowStatusLatestService` package imports and CI status …
prakash100198 083fd43
Merge remote-tracking branch 'origin/optimize-ci-cd-workflow' into cd…
iamayushm 03f78d4
circular import fix
iamayushm 677f569
Merge pull request #6748 from devtron-labs/cd-get-optimised
iamayushm 48468ce
refactoring
iamayushm 8cd66fe
Merge remote-tracking branch 'origin/optimize-ci-cd-workflow' into cd…
iamayushm 61a1c74
opt (#6747)
prkhrkat 1368559
removed extra code
prkhrkat 20dc988
dev testing fixes
iamayushm b6156f0
dev testing changes
iamayushm 4443e57
opt
iamayushm 714107a
Remove redundant workflow status update logic for CI/CD workflows and…
prakash100198 ca578cf
changing slow query
iamayushm df5fb33
Remove `WorkflowStatusUpdateService` and update references to streaml…
prakash100198 58895c6
Merge remote-tracking branch 'origin/optimize-ci-cd-workflow' into op…
prakash100198 6ecb09b
Remove legacy CI/CD workflow status fetching methods and streamline i…
prakash100198 aae32f6
Remove unused methods from `WorkflowStatusLatestRepository` to stream…
prakash100198 ee5672e
Update unique constraints in workflow status tables to use `ci_workfl…
prakash100198 b86f98f
Update `WorkflowStatusLatestService` to handle both create and update…
prakash100198 197a9dc
fix: refactored unit conversion for cluster details (#6768)
SATYAsasini 35f4e38
develop merge
iamayushm 797bc2c
develop merge
iamayushm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
195 changes: 195 additions & 0 deletions
195
internal/sql/repository/pipelineConfig/WorkflowStatusLatestRepository.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
/* | ||
* Copyright (c) 2024. Devtron Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package pipelineConfig | ||
|
||
import ( | ||
"github.com/devtron-labs/devtron/pkg/sql" | ||
"github.com/go-pg/pg" | ||
"go.uber.org/zap" | ||
) | ||
|
||
type WorkflowStatusLatestRepository interface { | ||
// CI Workflow Status Latest methods | ||
SaveCiWorkflowStatusLatest(model *CiWorkflowStatusLatest) error | ||
UpdateCiWorkflowStatusLatest(model *CiWorkflowStatusLatest) error | ||
GetCiWorkflowStatusLatestByPipelineId(pipelineId int) (*CiWorkflowStatusLatest, error) | ||
GetCiWorkflowStatusLatestByAppId(appId int) ([]*CiWorkflowStatusLatest, error) | ||
DeleteCiWorkflowStatusLatestByPipelineId(pipelineId int) error | ||
|
||
// CD Workflow Status Latest methods | ||
SaveCdWorkflowStatusLatest(model *CdWorkflowStatusLatest) error | ||
UpdateCdWorkflowStatusLatest(model *CdWorkflowStatusLatest) error | ||
GetCdWorkflowStatusLatestByPipelineIdAndWorkflowType(pipelineId int, workflowType string) (*CdWorkflowStatusLatest, error) | ||
GetCdWorkflowStatusLatestByAppId(appId int) ([]*CdWorkflowStatusLatest, error) | ||
GetCdWorkflowStatusLatestByPipelineId(pipelineId int) ([]*CdWorkflowStatusLatest, error) | ||
DeleteCdWorkflowStatusLatestByPipelineId(pipelineId int) error | ||
} | ||
|
||
type WorkflowStatusLatestRepositoryImpl struct { | ||
dbConnection *pg.DB | ||
logger *zap.SugaredLogger | ||
} | ||
|
||
func NewWorkflowStatusLatestRepositoryImpl(dbConnection *pg.DB, logger *zap.SugaredLogger) *WorkflowStatusLatestRepositoryImpl { | ||
return &WorkflowStatusLatestRepositoryImpl{ | ||
dbConnection: dbConnection, | ||
logger: logger, | ||
} | ||
} | ||
|
||
// CI Workflow Status Latest model | ||
type CiWorkflowStatusLatest struct { | ||
tableName struct{} `sql:"ci_workflow_status_latest" pg:",discard_unknown_columns"` | ||
Id int `sql:"id,pk"` | ||
PipelineId int `sql:"pipeline_id"` | ||
AppId int `sql:"app_id"` | ||
CiWorkflowId int `sql:"ci_workflow_id"` | ||
sql.AuditLog | ||
} | ||
|
||
// CD Workflow Status Latest model | ||
type CdWorkflowStatusLatest struct { | ||
tableName struct{} `sql:"cd_workflow_status_latest" pg:",discard_unknown_columns"` | ||
Id int `sql:"id,pk"` | ||
PipelineId int `sql:"pipeline_id"` | ||
AppId int `sql:"app_id"` | ||
EnvironmentId int `sql:"environment_id"` | ||
WorkflowType string `sql:"workflow_type"` | ||
WorkflowRunnerId int `sql:"workflow_runner_id"` | ||
sql.AuditLog | ||
} | ||
|
||
// CI Workflow Status Latest methods implementation | ||
func (impl *WorkflowStatusLatestRepositoryImpl) SaveCiWorkflowStatusLatest(model *CiWorkflowStatusLatest) error { | ||
err := impl.dbConnection.Insert(model) | ||
if err != nil { | ||
impl.logger.Errorw("error in saving ci workflow status latest", "err", err, "model", model) | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func (impl *WorkflowStatusLatestRepositoryImpl) UpdateCiWorkflowStatusLatest(model *CiWorkflowStatusLatest) error { | ||
_, err := impl.dbConnection.Model(model).WherePK().UpdateNotNull() | ||
if err != nil { | ||
impl.logger.Errorw("error in updating ci workflow status latest", "err", err, "model", model) | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func (impl *WorkflowStatusLatestRepositoryImpl) GetCiWorkflowStatusLatestByPipelineId(pipelineId int) (*CiWorkflowStatusLatest, error) { | ||
model := &CiWorkflowStatusLatest{} | ||
err := impl.dbConnection.Model(model). | ||
Where("pipeline_id = ?", pipelineId). | ||
Select() | ||
if err != nil { | ||
impl.logger.Errorw("error in getting ci workflow status latest by pipeline id", "err", err, "pipelineId", pipelineId) | ||
return nil, err | ||
} | ||
return model, nil | ||
} | ||
|
||
func (impl *WorkflowStatusLatestRepositoryImpl) GetCiWorkflowStatusLatestByAppId(appId int) ([]*CiWorkflowStatusLatest, error) { | ||
var models []*CiWorkflowStatusLatest | ||
err := impl.dbConnection.Model(&models). | ||
Where("app_id = ?", appId). | ||
Select() | ||
if err != nil { | ||
impl.logger.Errorw("error in getting ci workflow status latest by app id", "err", err, "appId", appId) | ||
return nil, err | ||
} | ||
return models, nil | ||
} | ||
|
||
func (impl *WorkflowStatusLatestRepositoryImpl) DeleteCiWorkflowStatusLatestByPipelineId(pipelineId int) error { | ||
_, err := impl.dbConnection.Model(&CiWorkflowStatusLatest{}). | ||
Where("pipeline_id = ?", pipelineId). | ||
Delete() | ||
if err != nil { | ||
impl.logger.Errorw("error in deleting ci workflow status latest by pipeline id", "err", err, "pipelineId", pipelineId) | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
// CD Workflow Status Latest methods implementation | ||
func (impl *WorkflowStatusLatestRepositoryImpl) SaveCdWorkflowStatusLatest(model *CdWorkflowStatusLatest) error { | ||
err := impl.dbConnection.Insert(model) | ||
if err != nil { | ||
impl.logger.Errorw("error in saving cd workflow status latest", "err", err, "model", model) | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func (impl *WorkflowStatusLatestRepositoryImpl) UpdateCdWorkflowStatusLatest(model *CdWorkflowStatusLatest) error { | ||
_, err := impl.dbConnection.Model(model).WherePK().UpdateNotNull() | ||
if err != nil { | ||
impl.logger.Errorw("error in updating cd workflow status latest", "err", err, "model", model) | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func (impl *WorkflowStatusLatestRepositoryImpl) GetCdWorkflowStatusLatestByPipelineIdAndWorkflowType(pipelineId int, workflowType string) (*CdWorkflowStatusLatest, error) { | ||
model := &CdWorkflowStatusLatest{} | ||
err := impl.dbConnection.Model(model). | ||
Where("pipeline_id = ?", pipelineId). | ||
Where("workflow_type = ?", workflowType). | ||
Select() | ||
if err != nil { | ||
impl.logger.Errorw("error in getting cd workflow status latest by pipeline id and workflow type", "err", err, "pipelineId", pipelineId, "workflowType", workflowType) | ||
return nil, err | ||
} | ||
return model, nil | ||
} | ||
|
||
func (impl *WorkflowStatusLatestRepositoryImpl) GetCdWorkflowStatusLatestByAppId(appId int) ([]*CdWorkflowStatusLatest, error) { | ||
var models []*CdWorkflowStatusLatest | ||
err := impl.dbConnection.Model(&models). | ||
Where("app_id = ?", appId). | ||
Select() | ||
if err != nil { | ||
impl.logger.Errorw("error in getting cd workflow status latest by app id", "err", err, "appId", appId) | ||
return nil, err | ||
} | ||
return models, nil | ||
} | ||
|
||
func (impl *WorkflowStatusLatestRepositoryImpl) GetCdWorkflowStatusLatestByPipelineId(pipelineId int) ([]*CdWorkflowStatusLatest, error) { | ||
var models []*CdWorkflowStatusLatest | ||
err := impl.dbConnection.Model(&models). | ||
Where("pipeline_id = ?", pipelineId). | ||
Select() | ||
if err != nil { | ||
impl.logger.Errorw("error in getting cd workflow status latest by pipeline id", "err", err, "pipelineId", pipelineId) | ||
return nil, err | ||
} | ||
return models, nil | ||
} | ||
|
||
func (impl *WorkflowStatusLatestRepositoryImpl) DeleteCdWorkflowStatusLatestByPipelineId(pipelineId int) error { | ||
_, err := impl.dbConnection.Model(&CdWorkflowStatusLatest{}). | ||
Where("pipeline_id = ?", pipelineId). | ||
Delete() | ||
if err != nil { | ||
impl.logger.Errorw("error in deleting cd workflow status latest by pipeline id", "err", err, "pipelineId", pipelineId) | ||
return err | ||
} | ||
return nil | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.