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 8bcf9ea7d6 Adding task status data models
8bcf9ea7d6 is described below
commit 8bcf9ea7d6a4c328b8e97cd8f57d030a453a3169
Author: DImuthuUpe <[email protected]>
AuthorDate: Thu Nov 5 07:13:08 2026 -0500
Adding task status data models
---
api/process/model/task.go | 98 +++++++++++++++++++++++++++
internal/db/migrate.go | 4 ++
internal/db/migrate_test.go | 2 +-
internal/db/migrations/0004_task_statuses.sql | 13 ++++
4 files changed, 116 insertions(+), 1 deletion(-)
diff --git a/api/process/model/task.go b/api/process/model/task.go
index 5d345cf9d8..997bba8108 100644
--- a/api/process/model/task.go
+++ b/api/process/model/task.go
@@ -183,3 +183,101 @@ func (t *InteractiveCommandTask) BeforeCreate(*gorm.DB)
error {
func (t *InteractiveCommandTask) BelongsTo(processID string) bool {
return t.ProcessID != nil && *t.ProcessID == processID
}
+
+// TaskType names which of the four task tables a TaskStatus points into.
+type TaskType string
+
+const (
+ TaskTypeDataStaging TaskType = "DATA_STAGING"
+ TaskTypeJobSubmission TaskType = "JOB_SUBMISSION"
+ TaskTypeJobMonitoring TaskType = "JOB_MONITORING"
+ TaskTypeInteractiveCommand TaskType = "INTERACTIVE_COMMAND"
+)
+
+// Valid reports whether t is a recognised task type.
+func (t TaskType) Valid() bool {
+ switch t {
+ case TaskTypeDataStaging, TaskTypeJobSubmission, TaskTypeJobMonitoring,
TaskTypeInteractiveCommand:
+ return true
+ }
+ return false
+}
+
+type TaskStatusType string
+
+const (
+ TaskStatusTypeCreated TaskStatusType = "CREATED"
+ TaskStatusTypeExecuting TaskStatusType = "EXECUTING"
+ // The task is blocked on something outside the workflow, such as an
interactive
+ // authentication, and resumes once it arrives.
+ TaskStatusTypePaused TaskStatusType = "PAUSED"
+ TaskStatusTypeCompleted TaskStatusType = "COMPLETED"
+ TaskStatusTypeFailed TaskStatusType = "FAILED"
+ TaskStatusTypeCanceled TaskStatusType = "CANCELED"
+)
+
+// Valid reports whether s is a recognised task status.
+func (s TaskStatusType) Valid() bool {
+ switch s {
+ case TaskStatusTypeCreated, TaskStatusTypeExecuting,
TaskStatusTypePaused,
+ TaskStatusTypeCompleted, TaskStatusTypeFailed,
TaskStatusTypeCanceled:
+ return true
+ }
+ return false
+}
+
+// TaskStatus is one entry in a task's status history.
+//
+// The four task kinds live in four tables, so TaskID cannot carry a foreign
key; TaskType
+// says which table it names. Cleanup is split accordingly: deleting a process
cascades
+// through ProcessID, and deleting a single task removes its history in the
task's
+// AfterDelete.
+type TaskStatus struct {
+ ID string `gorm:"column:task_status_id;primaryKey;type:varchar(36)"
json:"taskStatusId"`
+
+ TaskID string `gorm:"column:task_id;type:varchar(36);not
null;index" json:"taskId"`
+ TaskType TaskType `gorm:"column:task_type;type:varchar(32);not null"
json:"taskType"`
+
+ ProcessID *string `gorm:"column:process_id;type:varchar(36);index"
json:"processId,omitempty"`
+ Process *Process
`gorm:"references:ID;constraint:OnDelete:CASCADE,OnUpdate:CASCADE" json:"-"`
+
+ Status *TaskStatusType `gorm:"column:status;type:varchar(255)"
json:"status,omitempty"`
+ Log *string `gorm:"column:log;type:text"
json:"log,omitempty"`
+
+ // The time the status was recorded, in milliseconds since the epoch.
+ Timestamp *int64 `gorm:"column:timestamp" json:"timestamp,omitempty"`
+}
+
+// TableName returns the table backing TaskStatus.
+func (TaskStatus) TableName() string { return "task_statuses" }
+
+// BeforeCreate assigns a UUID when none was supplied.
+func (s *TaskStatus) BeforeCreate(*gorm.DB) error {
+ if s.ID == "" {
+ s.ID = uuid.NewString()
+ }
+ return nil
+}
+
+// deleteTaskStatuses removes the status history of one task. It stands in for
the
+// cascade TaskStatus.TaskID cannot declare.
+func deleteTaskStatuses(tx *gorm.DB, taskID string) error {
+ if taskID == "" {
+ return nil
+ }
+ return tx.Where("task_id = ?", taskID).Delete(&TaskStatus{}).Error
+}
+
+// AfterDelete removes the task's status history.
+func (t *DataStagingTask) AfterDelete(tx *gorm.DB) error { return
deleteTaskStatuses(tx, t.ID) }
+
+// AfterDelete removes the task's status history.
+func (t *JobSubmissionTask) AfterDelete(tx *gorm.DB) error { return
deleteTaskStatuses(tx, t.ID) }
+
+// AfterDelete removes the task's status history.
+func (t *JobMonitoringTask) AfterDelete(tx *gorm.DB) error { return
deleteTaskStatuses(tx, t.ID) }
+
+// AfterDelete removes the task's status history.
+func (t *InteractiveCommandTask) AfterDelete(tx *gorm.DB) error {
+ return deleteTaskStatuses(tx, t.ID)
+}
diff --git a/internal/db/migrate.go b/internal/db/migrate.go
index 528b101e61..9f478907e5 100644
--- a/internal/db/migrate.go
+++ b/internal/db/migrate.go
@@ -98,6 +98,10 @@ func Entities() []any {
&processmodel.JobSubmissionTask{},
&processmodel.JobMonitoringTask{},
&processmodel.InteractiveCommandTask{},
+
+ // The status history of those steps. It references the process
rather than a
+ // task, since a task id may name a row in any of the four
tables above.
+ &processmodel.TaskStatus{},
}
}
diff --git a/internal/db/migrate_test.go b/internal/db/migrate_test.go
index 9b6245fe7c..22521aa9bd 100644
--- a/internal/db/migrate_test.go
+++ b/internal/db/migrate_test.go
@@ -73,7 +73,7 @@ func TestAutoMigrateCreatesEveryTable(t *testing.T) {
"processes", "batch_processes", "batch_process_statuses",
"process_statuses",
"process_template_input_mappings",
"process_template_output_mappings",
"data_staging_tasks", "job_submission_tasks",
"job_monitoring_tasks",
- "interactive_command_tasks",
+ "interactive_command_tasks", "task_statuses",
}
for _, table := range want {
if !gdb.Migrator().HasTable(table) {
diff --git a/internal/db/migrations/0004_task_statuses.sql
b/internal/db/migrations/0004_task_statuses.sql
new file mode 100644
index 0000000000..12158f9183
--- /dev/null
+++ b/internal/db/migrations/0004_task_statuses.sql
@@ -0,0 +1,13 @@
+-- Record a status history for process tasks.
+--
+-- A task id may name a row in any of the four task tables, so task_id carries
no
+-- foreign key and task_type says which table it points into. The process
reference is
+-- what removes the history with its run; a single task's history is removed
by that
+-- task's AfterDelete hook. The DDL is what AutoMigrate emits for TaskStatus —
see
+-- TestBaselineMigrationMatchesAutoMigrate.
+
+CREATE TABLE "task_statuses" ("task_status_id" varchar(36),"task_id"
varchar(36) NOT NULL,"task_type" varchar(32) NOT NULL,"process_id"
varchar(36),"status" varchar(255),"log" text,"timestamp" bigint,PRIMARY KEY
("task_status_id"),CONSTRAINT "fk_task_statuses_process" FOREIGN KEY
("process_id") REFERENCES "processes"("process_id") ON DELETE CASCADE ON UPDATE
CASCADE);
+
+CREATE INDEX IF NOT EXISTS "idx_task_statuses_process_id" ON "task_statuses"
("process_id");
+
+CREATE INDEX IF NOT EXISTS "idx_task_statuses_task_id" ON "task_statuses"
("task_id");