This is an automated email from the ASF dual-hosted git repository.
DImuthuUpe pushed a commit to branch workflow-pause-on-auth
in repository https://gitbox.apache.org/repos/asf/airavata.git
The following commit(s) were added to refs/heads/workflow-pause-on-auth by this
push:
new f9392bc213 Recording process execution completion
f9392bc213 is described below
commit f9392bc2133ad195a0f2253c4bfdd01eed2345a2
Author: DImuthuUpe <[email protected]>
AuthorDate: Sat Nov 7 00:24:38 2026 -0500
Recording process execution completion
---
api/process/repository/execution.go | 38 +++++++++++++++++++++++++++
api/process/service/execution.go | 31 ++--------------------
internal/app/app.go | 2 +-
internal/orchestration/engine.go | 2 ++
internal/orchestration/workflows/workflows.go | 9 +++++++
5 files changed, 52 insertions(+), 30 deletions(-)
diff --git a/api/process/repository/execution.go
b/api/process/repository/execution.go
index 9dd60ec3d0..987c6c415d 100644
--- a/api/process/repository/execution.go
+++ b/api/process/repository/execution.go
@@ -22,9 +22,13 @@ package repository
import (
"context"
+ "errors"
+ "time"
"gorm.io/gorm"
+ "github.com/apache/airavata/internal/ptr"
+
model "github.com/apache/airavata/api/process/model"
)
@@ -93,6 +97,40 @@ func (r *ExecutionRepository) UpdateStatus(ctx
context.Context, id string, statu
return nil
}
+// Record creates the execution of one workflow instance of a process, or
moves an
+// existing one to status. An update changes only the status: the type and
timestamp
+// stay as first recorded, so the timestamp keeps saying when the execution
started.
+//
+// It is here rather than only in the service so that the orchestration
activities,
+// which cannot import the service package, record executions the same way.
+func (r *ExecutionRepository) Record(ctx context.Context, processID,
executionID string,
+ executionType model.ProcessExecutionType, status
model.ProcessExecutionStatusType) (*model.ProcessExecution, error) {
+
+ existing, err := r.FindByExecutionIDAndProcessID(ctx, executionID,
processID)
+ switch {
+ case err == nil:
+ if err := r.UpdateStatus(ctx, existing.ID, status); err != nil {
+ return nil, err
+ }
+ existing.Status = &status
+ return existing, nil
+ case !errors.Is(err, gorm.ErrRecordNotFound):
+ return nil, err
+ }
+
+ created := &model.ProcessExecution{
+ ProcessID: &processID,
+ ExecutionID: executionID,
+ ExecutionType: &executionType,
+ Status: &status,
+ Timestamp: ptr.To(time.Now().UnixMilli()),
+ }
+ if err := r.Create(ctx, created); err != nil {
+ return nil, err
+ }
+ return created, nil
+}
+
// Create inserts an execution row. BeforeCreate assigns its id and AfterCreate
// repoints the owning process's LastExecutionID at it.
func (r *ExecutionRepository) Create(ctx context.Context, e
*model.ProcessExecution) error {
diff --git a/api/process/service/execution.go b/api/process/service/execution.go
index 56036f6b5d..40f1873add 100644
--- a/api/process/service/execution.go
+++ b/api/process/service/execution.go
@@ -22,14 +22,11 @@ package service
import (
"context"
- "errors"
- "time"
"gorm.io/gorm"
"github.com/apache/airavata/internal/auth"
"github.com/apache/airavata/internal/httpx"
- "github.com/apache/airavata/internal/ptr"
dto "github.com/apache/airavata/api/process/dto"
model "github.com/apache/airavata/api/process/model"
@@ -80,37 +77,13 @@ func (s *ExecutionService) Record(ctx context.Context,
processID, executionID st
// caller that is already inside one of its own commits or rolls back the
execution
// together with the rest of its work.
//
-// An update changes only the status. The type and timestamp stay as first
recorded,
-// so the timestamp keeps saying when the workflow was started.
+// See ExecutionRepository.Record for what an update changes.
func (s *ExecutionService) RecordTx(ctx context.Context, tx *gorm.DB,
processID, executionID string, executionType model.ProcessExecutionType, status
model.ProcessExecutionStatusType) (*model.ProcessExecution, error) {
if _, err := s.processes.WithTx(tx).FindByID(ctx, processID); err !=
nil {
return nil, notFoundAs(err, "Process not found: %s", processID)
}
- executions := s.executions.WithTx(tx)
- existing, err := executions.FindByExecutionIDAndProcessID(ctx,
executionID, processID)
- switch {
- case err == nil:
- if err := executions.UpdateStatus(ctx, existing.ID, status);
err != nil {
- return nil, err
- }
- existing.Status = &status
- return existing, nil
- case !errors.Is(err, gorm.ErrRecordNotFound):
- return nil, err
- }
-
- created := &model.ProcessExecution{
- ProcessID: &processID,
- ExecutionID: executionID,
- ExecutionType: &executionType,
- Status: &status,
- Timestamp: ptr.To(time.Now().UnixMilli()),
- }
- if err := executions.Create(ctx, created); err != nil {
- return nil, err
- }
- return created, nil
+ return s.executions.WithTx(tx).Record(ctx, processID, executionID,
executionType, status)
}
// ListForProcess returns every execution recorded for a process, oldest first.
diff --git a/internal/app/app.go b/internal/app/app.go
index 6c9219d5cd..e892dc8c61 100644
--- a/internal/app/app.go
+++ b/internal/app/app.go
@@ -219,7 +219,7 @@ func NewServices(cfg config.Config, db *gorm.DB, repos
*Repositories, workflowBa
sshCredentialSvc :=
credentialssvc.NewSSHCredentialService(sshCredentials, users, clusterConfigs,
storages)
executionEngine := orchestration.NewExecutionEngine(stagingTasks,
submissionTasks,
- monitoringTasks, storages, clusterConfigs, processes,
deployments, templates, batchStatus, statuses, repos.TaskStatuses,
workflowBackend, sshContext)
+ monitoringTasks, storages, clusterConfigs, processes,
deployments, templates, batchStatus, statuses, repos.TaskStatuses,
processExecutions, workflowBackend, sshContext)
executionEngine.StartEngine()
return &Services{
diff --git a/internal/orchestration/engine.go b/internal/orchestration/engine.go
index 38596e989d..260e07486e 100644
--- a/internal/orchestration/engine.go
+++ b/internal/orchestration/engine.go
@@ -70,6 +70,7 @@ func NewExecutionEngine(dataStagingTasks
*processrepo.DataStagingTaskRepository,
batchStatus *processrepo.BatchJobStatusRepository,
processStatus *processrepo.StatusRepository,
taskStatus *processrepo.TaskStatusRepository,
+ executions *processrepo.ExecutionRepository,
workflowBackend backend.Backend,
sshContext *ssh.GlobalSSHContext,
) *ExecutionEngine {
@@ -89,6 +90,7 @@ func NewExecutionEngine(dataStagingTasks
*processrepo.DataStagingTaskRepository,
batch.New(processes, jobSubmissionTasks,
slurmClusterConfigs, batchDeployments, templates, batchStatus, sshContext,
tracker),
monitoring.New(processes, jobMonitoringTasks, tracker),
dataStagingTasks, jobSubmissionTasks,
jobMonitoringTasks, processStatus,
+ executions,
),
orchestrator: orchestrator,
processes: processes,
diff --git a/internal/orchestration/workflows/workflows.go
b/internal/orchestration/workflows/workflows.go
index bfc1fb24aa..4579176f52 100644
--- a/internal/orchestration/workflows/workflows.go
+++ b/internal/orchestration/workflows/workflows.go
@@ -55,6 +55,7 @@ type Workflows struct {
jobSubmissionTasks *processrepo.JobSubmissionTaskRepository
jobMonitoringTasks *processrepo.JobMonitoringTaskRepository
processStatus *processrepo.StatusRepository
+ executionRepo *processrepo.ExecutionRepository
}
// New returns the workflows over the given tasks and the repositories they are
@@ -64,6 +65,7 @@ func New(data *data.Tasks, batch *batch.Tasks, monitoring
*monitoring.Tasks,
jobSubmissionTasks *processrepo.JobSubmissionTaskRepository,
jobMonitoringTasks *processrepo.JobMonitoringTaskRepository,
processStatus *processrepo.StatusRepository,
+ executionRepo *processrepo.ExecutionRepository,
) *Workflows {
return &Workflows{
data: data,
@@ -73,6 +75,7 @@ func New(data *data.Tasks, batch *batch.Tasks, monitoring
*monitoring.Tasks,
jobSubmissionTasks: jobSubmissionTasks,
jobMonitoringTasks: jobMonitoringTasks,
processStatus: processStatus,
+ executionRepo: executionRepo,
}
}
@@ -167,6 +170,12 @@ func (w *Workflows) HandleBatchJobCompletion(ctx
workflow.Context, processID str
return err
}
+ // record workflow completion
+ if _, err := w.executionRepo.Record(ctxInt, processID,
workflow.WorkflowInstance(ctx).InstanceID,
model.ProcessExecutionTypeBatchJobSubmission,
model.ProcessExecutionStatusTypeSucceeded); err != nil {
+ slog.Error("Failed to record execution", "processId",
processID, "error", err)
+ return err
+ }
+
return nil
}