Skip to content

Commit 17c1dae

Browse files
committed
Refactor workflow status handling: rename WorkflowStatusLatestService package, integrate optimized CI status fetching and fallback logic in CiHandlerImpl.
1 parent 604baa8 commit 17c1dae

File tree

6 files changed

+24
-10
lines changed

6 files changed

+24
-10
lines changed

pkg/pipeline/CiHandler.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
eventProcessorBean "github.com/devtron-labs/devtron/pkg/eventProcessor/bean"
3030
"github.com/devtron-labs/devtron/pkg/pipeline/constants"
3131
"github.com/devtron-labs/devtron/pkg/pipeline/workflowStatus"
32+
"github.com/devtron-labs/devtron/pkg/workflow/status/workflowStatusLatest"
3233
"regexp"
3334
"slices"
3435
"strconv"
@@ -97,13 +98,15 @@ type CiHandlerImpl struct {
9798
config *types.CiConfig
9899
k8sCommonService k8sPkg.K8sCommonService
99100
workFlowStageStatusService workflowStatus.WorkFlowStageStatusService
101+
workflowStatusUpdateService workflowStatusLatest.WorkflowStatusUpdateService
100102
}
101103

102104
func NewCiHandlerImpl(Logger *zap.SugaredLogger, ciService CiService, ciPipelineMaterialRepository pipelineConfig.CiPipelineMaterialRepository, gitSensorClient gitSensor.Client, ciWorkflowRepository pipelineConfig.CiWorkflowRepository,
103105
ciArtifactRepository repository.CiArtifactRepository, userService user.UserService, eventClient client.EventClient, eventFactory client.EventFactory, ciPipelineRepository pipelineConfig.CiPipelineRepository,
104106
appListingRepository repository.AppListingRepository, cdPipelineRepository pipelineConfig.PipelineRepository, enforcerUtil rbac.EnforcerUtil, resourceGroupService resourceGroup.ResourceGroupService, envRepository repository2.EnvironmentRepository,
105107
imageTaggingService imageTagging.ImageTaggingService, k8sCommonService k8sPkg.K8sCommonService, appWorkflowRepository appWorkflow.AppWorkflowRepository, customTagService CustomTagService,
106108
workFlowStageStatusService workflowStatus.WorkFlowStageStatusService,
109+
workflowStatusUpdateService workflowStatusLatest.WorkflowStatusUpdateService,
107110
) *CiHandlerImpl {
108111
cih := &CiHandlerImpl{
109112
Logger: Logger,
@@ -126,6 +129,7 @@ func NewCiHandlerImpl(Logger *zap.SugaredLogger, ciService CiService, ciPipeline
126129
appWorkflowRepository: appWorkflowRepository,
127130
k8sCommonService: k8sCommonService,
128131
workFlowStageStatusService: workFlowStageStatusService,
132+
workflowStatusUpdateService: workflowStatusUpdateService,
129133
}
130134
config, err := types.GetCiConfig()
131135
if err != nil {
@@ -644,10 +648,15 @@ func (impl *CiHandlerImpl) stateChanged(status string, podStatus string, msg str
644648
}
645649

646650
func (impl *CiHandlerImpl) FetchCiStatusForTriggerViewV1(appId int) ([]*pipelineConfig.CiWorkflowStatus, error) {
647-
ciWorkflowStatuses, err := impl.ciWorkflowRepository.FIndCiWorkflowStatusesByAppId(appId)
648-
if err != nil && !util.IsErrNoRows(err) {
649-
impl.Logger.Errorw("err in fetching ciWorkflowStatuses from ciWorkflowRepository", "appId", appId, "err", err)
650-
return ciWorkflowStatuses, err
651+
ciWorkflowStatuses, err := impl.workflowStatusUpdateService.FetchCiStatusForTriggerViewOptimized(appId)
652+
if err != nil {
653+
impl.Logger.Errorw("error in fetching ci status from optimized service, falling back to old method", "appId", appId, "err", err)
654+
// Fallback to old method if optimized service fails
655+
ciWorkflowStatuses, err = impl.ciWorkflowRepository.FIndCiWorkflowStatusesByAppId(appId)
656+
if err != nil && !util.IsErrNoRows(err) {
657+
impl.Logger.Errorw("err in fetching ciWorkflowStatuses from ciWorkflowRepository", "appId", appId, "err", err)
658+
return ciWorkflowStatuses, err
659+
}
651660
}
652661

653662
return ciWorkflowStatuses, err

pkg/workflow/status/WorkflowStatusLatestService.go renamed to pkg/workflow/status/workflowStatusLatest/WorkflowStatusLatestService.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package status
17+
package workflowStatusLatest
1818

1919
import (
2020
util2 "github.com/devtron-labs/devtron/internal/util"

pkg/workflow/status/WorkflowStatusUpdateService.go renamed to pkg/workflow/status/workflowStatusLatest/WorkflowStatusUpdateService.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package status
17+
package workflowStatusLatest
1818

1919
import (
2020
"github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig"

pkg/workflow/status/wire_workflow_status_latest.go renamed to pkg/workflow/status/workflowStatusLatest/wire_workflow_status_latest.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package status
17+
package workflowStatusLatest
1818

1919
import (
2020
"github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig"

pkg/workflow/wire_workflow.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package workflow
1919
import (
2020
"github.com/devtron-labs/devtron/pkg/workflow/cd"
2121
"github.com/devtron-labs/devtron/pkg/workflow/status"
22+
"github.com/devtron-labs/devtron/pkg/workflow/status/workflowStatusLatest"
2223
"github.com/devtron-labs/devtron/pkg/workflow/trigger/audit/hook"
2324
"github.com/devtron-labs/devtron/pkg/workflow/trigger/audit/repository"
2425
"github.com/devtron-labs/devtron/pkg/workflow/trigger/audit/service"
@@ -28,7 +29,7 @@ import (
2829
var WorkflowWireSet = wire.NewSet(
2930
cd.CdWorkflowWireSet,
3031
status.WorkflowStatusWireSet,
31-
status.WorkflowStatusLatestWireSet,
32+
workflowStatusLatest.WorkflowStatusLatestWireSet,
3233
hook.NewTriggerAuditHookImpl,
3334
wire.Bind(new(hook.TriggerAuditHook), new(*hook.TriggerAuditHookImpl)),
3435
service.NewWorkflowTriggerAuditServiceImpl,

wire_gen.go

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)