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 6e7a93a18d Adding ProcessExecutionStatusType to execution
6e7a93a18d is described below
commit 6e7a93a18dda2be1385f1f073618bf0b34a1c464
Author: DImuthuUpe <[email protected]>
AuthorDate: Fri Nov 6 23:23:43 2026 -0500
Adding ProcessExecutionStatusType to execution
---
api/process/dto/execution.go | 12 ++++---
api/process/model/process.go | 11 ++++++
api/process/repository/execution.go | 31 +++++++++++++++--
api/process/service/execution.go | 39 +++++++++++++++++-----
api/process/service/launch.go | 9 +++++
docs/api.md | 6 +++-
docs/openapi.yaml | 10 ++++++
internal/app/app.go | 6 ++--
.../migrations/0006_process_execution_status.sql | 6 ++++
internal/server/server_test.go | 30 +++++++++++++----
10 files changed, 134 insertions(+), 26 deletions(-)
diff --git a/api/process/dto/execution.go b/api/process/dto/execution.go
index 5e15e2947f..97f5a7025e 100644
--- a/api/process/dto/execution.go
+++ b/api/process/dto/execution.go
@@ -28,11 +28,12 @@ import (
// StatusResponse it has no request counterpart: executions are recorded when a
// workflow is started for a process, never accepted from a client.
type ExecutionResponse struct {
- ProcessExecutionID string
`json:"processExecutionId"`
- ProcessID *string `json:"processId"`
- ExecutionID string `json:"executionId"`
- ExecutionType *model.ProcessExecutionType `json:"executionType"`
- Timestamp *int64 `json:"timestamp"`
+ ProcessExecutionID string
`json:"processExecutionId"`
+ ProcessID *string `json:"processId"`
+ ExecutionID string
`json:"executionId"`
+ ExecutionType *model.ProcessExecutionType
`json:"executionType"`
+ Status *model.ProcessExecutionStatusType `json:"status"`
+ Timestamp *int64 `json:"timestamp"`
}
func ToExecutionResponse(e *model.ProcessExecution) ExecutionResponse {
@@ -41,6 +42,7 @@ func ToExecutionResponse(e *model.ProcessExecution)
ExecutionResponse {
ProcessID: e.ProcessID,
ExecutionID: e.ExecutionID,
ExecutionType: e.ExecutionType,
+ Status: e.Status,
Timestamp: e.Timestamp,
}
}
diff --git a/api/process/model/process.go b/api/process/model/process.go
index c896bffff5..e87e32bed8 100644
--- a/api/process/model/process.go
+++ b/api/process/model/process.go
@@ -236,6 +236,14 @@ const (
ProcessExecutionTypeJobCompletion ProcessExecutionType =
"BATCH_JOB_COMPLETION"
)
+type ProcessExecutionStatusType string
+
+const (
+ ProcessExecutionStatusTypeRunning ProcessExecutionStatusType =
"RUNNING"
+ ProcessExecutionStatusTypeSucceeded ProcessExecutionStatusType =
"SUCCEEDED"
+ ProcessExecutionStatusTypeFailed ProcessExecutionStatusType =
"FAILED"
+)
+
// ProcessExecution records one workflow run started on behalf of a process —
the job
// submission, monitoring or completion workflow — by the id the workflow
engine knows
// it by.
@@ -248,6 +256,9 @@ type ProcessExecution struct {
ExecutionID string
`gorm:"column:execution_id;type:varchar(36)" json:"executionId"`
ExecutionType *ProcessExecutionType
`gorm:"column:execution_type;type:varchar(255)" json:"executionType,omitempty"`
+ // Where the run stands: RUNNING once started, then SUCCEEDED or FAILED.
+ Status *ProcessExecutionStatusType
`gorm:"column:status;type:varchar(255)" json:"status,omitempty"`
+
// The time the execution was recorded, in milliseconds since the epoch.
Timestamp *int64 `gorm:"column:timestamp" json:"timestamp,omitempty"`
}
diff --git a/api/process/repository/execution.go
b/api/process/repository/execution.go
index 217b668812..9dd60ec3d0 100644
--- a/api/process/repository/execution.go
+++ b/api/process/repository/execution.go
@@ -30,8 +30,8 @@ import (
// ExecutionRepository reads and writes process executions.
//
-// There is no Update: an execution records a workflow run that was started,
which is
-// never corrected in place.
+// Only an execution's status is ever updated: the rest records a workflow run
that was
+// started, which is never corrected in place.
type ExecutionRepository struct{ db *gorm.DB }
// NewExecutionRepository returns a repository backed by db.
@@ -66,6 +66,33 @@ func (r *ExecutionRepository) FindByIDAndProcessID(ctx
context.Context, id, proc
return &out, nil
}
+// FindByExecutionIDAndProcessID returns the execution recorded for one
workflow
+// instance of one process, or gorm.ErrRecordNotFound if none was.
+func (r *ExecutionRepository) FindByExecutionIDAndProcessID(ctx
context.Context, executionID, processID string) (*model.ProcessExecution,
error) {
+ var out model.ProcessExecution
+ err := r.db.WithContext(ctx).
+ First(&out, "execution_id = ? AND process_id = ?", executionID,
processID).Error
+ if err != nil {
+ return nil, err
+ }
+ return &out, nil
+}
+
+// UpdateStatus sets the status of one execution, or returns
gorm.ErrRecordNotFound if
+// no execution has that id.
+func (r *ExecutionRepository) UpdateStatus(ctx context.Context, id string,
status model.ProcessExecutionStatusType) error {
+ res := r.db.WithContext(ctx).Model(&model.ProcessExecution{}).
+ Where("process_execution_id = ?", id).
+ Update("status", status)
+ if res.Error != nil {
+ return res.Error
+ }
+ if res.RowsAffected == 0 {
+ return gorm.ErrRecordNotFound
+ }
+ return 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 e58d7e63e3..56036f6b5d 100644
--- a/api/process/service/execution.go
+++ b/api/process/service/execution.go
@@ -22,6 +22,7 @@ package service
import (
"context"
+ "errors"
"time"
"gorm.io/gorm"
@@ -52,18 +53,21 @@ func NewExecutionService(db *gorm.DB, executions
*repository.ExecutionRepository
return &ExecutionService{db: db, executions: executions, processes:
processes}
}
-// Record appends a new execution for a process, in its own transaction.
+// Record records where a workflow execution of a process stands, in its own
+// transaction: the first call for an executionID creates the execution, and
later
+// calls for the same one move it to the new status — RUNNING when the
workflow is
+// started, SUCCEEDED or FAILED when it finishes.
//
// It does not check authorisation: recording an execution is an internal
operation
// performed by trusted service code, never taken directly from a client
request.
-func (s *ExecutionService) Record(ctx context.Context, processID, executionID
string, executionType model.ProcessExecutionType) (*dto.ExecutionResponse,
error) {
+func (s *ExecutionService) Record(ctx context.Context, processID, executionID
string, executionType model.ProcessExecutionType, status
model.ProcessExecutionStatusType) (*dto.ExecutionResponse, error) {
var out dto.ExecutionResponse
err := s.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
- created, err := s.RecordTx(ctx, tx, processID, executionID,
executionType)
+ recorded, err := s.RecordTx(ctx, tx, processID, executionID,
executionType, status)
if err != nil {
return err
}
- out = dto.ToExecutionResponse(created)
+ out = dto.ToExecutionResponse(recorded)
return nil
})
if err != nil {
@@ -72,21 +76,38 @@ func (s *ExecutionService) Record(ctx context.Context,
processID, executionID st
return &out, nil
}
-// RecordTx appends a new execution inside an already-open transaction, so a
caller
-// that is already inside one of its own commits or rolls back the execution
together
-// with the rest of its work.
-func (s *ExecutionService) RecordTx(ctx context.Context, tx *gorm.DB,
processID, executionID string, executionType model.ProcessExecutionType)
(*model.ProcessExecution, error) {
+// RecordTx creates or updates an execution inside an already-open
transaction, so a
+// 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.
+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 := s.executions.WithTx(tx).Create(ctx, created); err != nil {
+ if err := executions.Create(ctx, created); err != nil {
return nil, err
}
return created, nil
diff --git a/api/process/service/launch.go b/api/process/service/launch.go
index f2ed4bf40c..2e47310003 100644
--- a/api/process/service/launch.go
+++ b/api/process/service/launch.go
@@ -60,6 +60,7 @@ type LaunchService struct {
scpDataStorageService *datasev.SCPDataStorageService
dataProductService *datasev.DataProductService
statusService *StatusService
+ executionService *ExecutionService
dataStagingTasks *repository.DataStagingTaskRepository
jobSubmissionTasks *repository.JobSubmissionTaskRepository
@@ -81,6 +82,7 @@ func NewLaunchService(
scpDataStorageService *datasev.SCPDataStorageService,
dataProductService *datasev.DataProductService,
statusService *StatusService,
+ executionService *ExecutionService,
dataStagingTasks *repository.DataStagingTaskRepository,
jobSubmissionTasks *repository.JobSubmissionTaskRepository,
@@ -105,6 +107,7 @@ func NewLaunchService(
monitoringTasks: monitoringTasks,
interactiveTasks: interactiveTasks,
executionEngine: executionEngine,
+ executionService: executionService,
}
}
@@ -276,6 +279,12 @@ func (s *LaunchService) launchBatchProcess(ctx
context.Context, process *dto.Res
return err
}
+ _, err = s.executionService.Record(ctx, process.ProcessID, workflowId,
procmodel.ProcessExecutionTypeBatchJobSubmission,
procmodel.ProcessExecutionStatusTypeRunning)
+
+ if err != nil {
+ slog.Error("Failed to record execution", "processId",
process.ProcessID, "error", err)
+ return err
+ }
slog.Info("Launched batch job submission", "processId",
process.ProcessID, "workflowId", workflowId)
if _, err := s.statusService.Record(ctx, process.ProcessID,
procmodel.ProcessStatusTypeSubmitted, nil); err != nil {
diff --git a/docs/api.md b/docs/api.md
index 3af9afe51e..345f6d428d 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -2058,13 +2058,17 @@ as `lastExecutionId`, which stays `null` until the
first workflow is started.
"processId": "a1b2c3d4-e5f6-4708-9a1b-2c3d4e5f6a7b",
"executionId": "e0d1c2b3-a4f5-4e6d-8c7b-9a0f1e2d3c4b",
"executionType": "BATCH_JOB_SUBMISSION",
+ "status": "RUNNING",
"timestamp": 1755780005000
}
]
```
`executionType` is one of `BATCH_JOB_SUBMISSION`, `JOB_MONITORING`,
-`BATCH_JOB_COMPLETION`. The `{executionId}` in the path is the entry's
+`BATCH_JOB_COMPLETION`. `status` is `RUNNING` once the workflow is started,
then
+`SUCCEEDED` or `FAILED` when it finishes; it is `null` for executions recorded
before
+the server tracked it. `timestamp` is when the execution was started and does
not
+change with its status. The `{executionId}` in the path is the entry's
`processExecutionId`, not the workflow engine's `executionId`.
Reads are owner-scoped: only the process's owner or an admin may list or read
its
diff --git a/docs/openapi.yaml b/docs/openapi.yaml
index 876f468f2a..7c1d356a11 100644
--- a/docs/openapi.yaml
+++ b/docs/openapi.yaml
@@ -2960,6 +2960,9 @@ components:
ProcessExecutionType:
type: string
enum: [BATCH_JOB_SUBMISSION, JOB_MONITORING, BATCH_JOB_COMPLETION]
+ ProcessExecutionStatusType:
+ type: string
+ enum: [RUNNING, SUCCEEDED, FAILED]
OnFailureAction:
type: string
enum: [RETRY, SKIP, EXIT]
@@ -3694,6 +3697,13 @@ components:
oneOf:
- { $ref: "#/components/schemas/ProcessExecutionType" }
- { type: "null" }
+ status:
+ description: |
+ `RUNNING` once the workflow is started, then `SUCCEEDED` or
`FAILED`. `null`
+ for executions recorded before the server tracked it.
+ oneOf:
+ - { $ref: "#/components/schemas/ProcessExecutionStatusType" }
+ - { type: "null" }
timestamp:
type: [integer, "null"]
format: int64
diff --git a/internal/app/app.go b/internal/app/app.go
index facd23fd7d..6c9219d5cd 100644
--- a/internal/app/app.go
+++ b/internal/app/app.go
@@ -192,8 +192,10 @@ func NewServices(cfg config.Config, db *gorm.DB, repos
*Repositories, workflowBa
monitoringTasks := repos.JobMonitoringTasks
commandTasks := repos.InteractiveCommandTasks
batchStatus := repos.BatchJobStatuses
+ processExecutions := repos.Executions
statusSvc := processsvc.NewStatusService(db, statuses, processes)
+ executionSvc := processsvc.NewExecutionService(db, processExecutions,
processes)
configAccess := computesvc.NewConfigAccess(clusterConfigs, shares,
groupMembers)
keyAccess := credentialssvc.NewKeyAccess(sshCredentials)
processSvs := processsvc.NewProcessService(db, processes, deployments,
configAccess, users, statusSvc)
@@ -255,7 +257,7 @@ func NewServices(cfg config.Config, db *gorm.DB, repos
*Repositories, workflowBa
Process: processSvs,
ProcessStatus: statusSvc,
TaskStatus:
processsvc.NewTaskStatusService(repos.TaskStatuses, processes),
- Execution: processsvc.NewExecutionService(db,
repos.Executions, processes),
+ Execution: executionSvc,
DataStagingTask:
processsvc.NewDataStagingTaskService(db, stagingTasks, processes),
JobSubmissionTask:
processsvc.NewJobSubmissionTaskService(db, submissionTasks, processes),
JobMonitoringTask:
processsvc.NewJobMonitoringTaskService(db, monitoringTasks, processes),
@@ -263,7 +265,7 @@ func NewServices(cfg config.Config, db *gorm.DB, repos
*Repositories, workflowBa
Launch: processsvc.NewLaunchService(db, processSvs,
batchDeploymentSvc,
templateSvc, slurmClusterSvc, slurmClusterConfigSvc,
- sshCredentialSvc, scpDataStorageSvc, dataProductSvc,
statusSvc, stagingTasks, submissionTasks,
+ sshCredentialSvc, scpDataStorageSvc, dataProductSvc,
statusSvc, executionSvc, stagingTasks, submissionTasks,
monitoringTasks, commandTasks, executionEngine),
ExecutionEngine: executionEngine,
diff --git a/internal/db/migrations/0006_process_execution_status.sql
b/internal/db/migrations/0006_process_execution_status.sql
new file mode 100644
index 0000000000..8ee4df612a
--- /dev/null
+++ b/internal/db/migrations/0006_process_execution_status.sql
@@ -0,0 +1,6 @@
+-- Record where each process execution stands: RUNNING once its workflow is
started,
+-- then SUCCEEDED or FAILED. Rows recorded before this column existed are left
NULL —
+-- their outcome was never captured. The DDL is what AutoMigrate emits for
+-- ProcessExecution.Status — see TestBaselineMigrationMatchesAutoMigrate.
+
+ALTER TABLE "process_executions" ADD COLUMN "status" varchar(255);
diff --git a/internal/server/server_test.go b/internal/server/server_test.go
index e82028faf8..fb937dd346 100644
--- a/internal/server/server_test.go
+++ b/internal/server/server_test.go
@@ -2607,15 +2607,15 @@ func TestExecutionsAreReadThroughTheirProcess(t
*testing.T) {
other := h.seedProcess("other-executions", tokenAlice)
ctx := context.Background()
- submission, err := h.svcs.Execution.Record(ctx, processID,
"workflow-1", "BATCH_JOB_SUBMISSION")
+ submission, err := h.svcs.Execution.Record(ctx, processID,
"workflow-1", "BATCH_JOB_SUBMISSION", "RUNNING")
if err != nil {
t.Fatalf("record submission: %v", err)
}
- completion, err := h.svcs.Execution.Record(ctx, processID,
"workflow-2", "BATCH_JOB_COMPLETION")
+ completion, err := h.svcs.Execution.Record(ctx, processID,
"workflow-2", "BATCH_JOB_COMPLETION", "RUNNING")
if err != nil {
t.Fatalf("record completion: %v", err)
}
- if _, err := h.svcs.Execution.Record(ctx, "no-such-process",
"workflow-3", "BATCH_JOB_SUBMISSION"); err == nil {
+ if _, err := h.svcs.Execution.Record(ctx, "no-such-process",
"workflow-3", "BATCH_JOB_SUBMISSION", "RUNNING"); err == nil {
t.Error("recording against an unknown process succeeded, want
an error")
}
@@ -2623,8 +2623,24 @@ func TestExecutionsAreReadThroughTheirProcess(t
*testing.T) {
if len(all) != 2 || all[0]["executionId"] != "workflow-1" ||
all[1]["executionId"] != "workflow-2" {
t.Fatalf("executions = %v, want workflow-1 then workflow-2",
all)
}
- if all[1]["executionType"] != "BATCH_JOB_COMPLETION" {
- t.Errorf("execution = %v, want it to name its type", all[1])
+ if all[1]["executionType"] != "BATCH_JOB_COMPLETION" ||
all[1]["status"] != "RUNNING" {
+ t.Errorf("execution = %v, want it to name its type and RUNNING
status", all[1])
+ }
+
+ // Recording the same workflow again moves its execution on rather than
adding one,
+ // keeping the type and start time it was first recorded with.
+ finished, err := h.svcs.Execution.Record(ctx, processID, "workflow-1",
"JOB_MONITORING", "SUCCEEDED")
+ if err != nil {
+ t.Fatalf("record finished submission: %v", err)
+ }
+ if finished.ProcessExecutionID != submission.ProcessExecutionID {
+ t.Errorf("re-recording created execution %s, want it to update
%s", finished.ProcessExecutionID, submission.ProcessExecutionID)
+ }
+ if *finished.ExecutionType != "BATCH_JOB_SUBMISSION" ||
*finished.Timestamp != *submission.Timestamp {
+ t.Errorf("re-recorded execution = %+v, want its original type
and timestamp", finished)
+ }
+ if again := h.list("/api/v1/processes/"+processID+"/executions",
tokenAlice); len(again) != 2 {
+ t.Errorf("executions after re-recording = %d, want still 2",
len(again))
}
proc := h.mustDo(http.MethodGet, "/api/v1/processes/"+processID,
tokenAlice, nil, http.StatusOK)
@@ -2633,8 +2649,8 @@ func TestExecutionsAreReadThroughTheirProcess(t
*testing.T) {
}
one := h.mustDo(http.MethodGet,
"/api/v1/processes/"+processID+"/executions/"+submission.ProcessExecutionID,
tokenAlice, nil, http.StatusOK)
- if one["executionId"] != "workflow-1" {
- t.Errorf("execution = %v, want workflow-1", one)
+ if one["executionId"] != "workflow-1" || one["status"] != "SUCCEEDED" {
+ t.Errorf("execution = %v, want workflow-1 SUCCEEDED", one)
}
// An execution id from one process reads nothing through another's
path.