wmedvede commented on code in PR #2911:
URL:
https://github.com/apache/incubator-kie-tools/pull/2911#discussion_r2004958128
##########
packages/sonataflow-operator/internal/controller/profiles/preview/deployment_handler.go:
##########
@@ -189,3 +209,69 @@ func (d *DeploymentReconciler)
deploymentModelMutateVisitors(
common.RestoreDeploymentVolumeAndVolumeMountMutateVisitor(),
common.RolloutDeploymentIfCMChangedMutateVisitor(workflow,
userPropsCM, managedPropsCM)}
}
+
+func (d *DeploymentReconciler) updateLastTimeStatusNotified(workflow
*operatorapi.SonataFlow, previousStatus operatorapi.SonataFlowStatus) {
+ previousRunningCondition :=
previousStatus.GetCondition(api.RunningConditionType)
+ currentRunningCondition :=
workflow.Status.GetCondition(api.RunningConditionType)
+
+ if previousRunningCondition == nil {
+ previousRunningCondition = currentRunningCondition
+ }
+ if previousRunningCondition.Status != currentRunningCondition.Status ||
workflow.Status.LastTimeStatusNotified != nil &&
workflow.Status.LastTimeStatusNotified.Time.Before(controllercommon.GetOperatorStartTime())
{
+ workflow.Status.LastTimeStatusNotified = nil
+ }
+}
+
+func (d *DeploymentReconciler) scheduleWorkflowStatusChangeNotification(ctx
context.Context, workflow *operatorapi.SonataFlow) {
+ if workflow.Status.LastTimeStatusNotified == nil {
+ controllercommon.GetSFCWorker().RunAsync(func() {
+ notifyWorkflowStatusChange(d.C, workflow.Name,
workflow.Namespace)
+ })
+ }
+}
+
+func notifyWorkflowStatusChange(cli client.Client, wfName, wfNamespace string)
error {
+ var err error
+ var uri string
+ retryErr := retry.RetryOnConflict(retry.DefaultBackoff, func() error {
+ workflow := &operatorapi.SonataFlow{}
+ if err = cli.Get(context.Background(),
types.NamespacedName{Name: wfName, Namespace: wfNamespace}, workflow); err !=
nil {
+ if errors.IsNotFound(err) {
+ klog.V(log.I).Infof("Workflow: %s, namespace:
%s, was not found to send the workflow definition status update event.",
wfName, wfNamespace)
+ return nil
+ } else {
+ klog.V(log.E).ErrorS(err,
constants.SendWorkflowDefinitionsStatusUpdateEventError+" It was not possible
to read the workflow.", "workflow", "namespace", wfName, wfNamespace)
+ return err
+ }
+ }
+ workflow = workflow.DeepCopy()
+ available :=
workflow.Status.GetCondition(api.RunningConditionType).IsTrue()
+ if uri, err = common.GetWorkflowDefinitionEventsTargetURL(cli,
workflow); err != nil {
+ klog.V(log.E).ErrorS(err,
constants.SendWorkflowDefinitionsStatusUpdateEventError+" Workflow definition
events target url calculation failed.", "workflow", "namespace", workflow.Name,
workflow.Namespace)
+ return err
+ }
+ if len(uri) == 0 {
+ klog.V(log.E).Infof("No enabled DataIndex, nor Broker,
nor Sink configuration was found to send the workflow definition status update
event for workflow: %s, namespace: %s", workflow.Name, workflow.Namespace)
Review Comment:
good catch, my fault.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]