harmonytask: remember machine

This commit is contained in:
Andrew Jackson (Ajax) 2023-11-13 11:53:36 -06:00
parent 06a0a69b2a
commit fea289fd2d
3 changed files with 12 additions and 9 deletions

View File

@ -0,0 +1 @@
ALTER TABLE harmony_task_history ADD COLUMN completed_by_host_and_port varchar(300) NOT NULL;

View File

@ -106,6 +106,7 @@ type TaskEngine struct {
follows map[string][]followStruct
lastFollowTime time.Time
lastCleanup atomic.Value
hostAndPort string
}
type followStruct struct {
f func(TaskID, AddTaskFunc) (bool, error)
@ -129,13 +130,14 @@ func New(
}
ctx, grace := context.WithCancel(context.Background())
e := &TaskEngine{
ctx: ctx,
grace: grace,
db: db,
reg: reg,
ownerID: reg.Resources.MachineID, // The current number representing "hostAndPort"
taskMap: make(map[string]*taskTypeHandler, len(impls)),
follows: make(map[string][]followStruct),
ctx: ctx,
grace: grace,
db: db,
reg: reg,
ownerID: reg.Resources.MachineID, // The current number representing "hostAndPort"
taskMap: make(map[string]*taskTypeHandler, len(impls)),
follows: make(map[string][]followStruct),
hostAndPort: hostnameAndPort,
}
e.lastCleanup.Store(time.Now())
for _, c := range impls {

View File

@ -198,8 +198,8 @@ func (h *taskTypeHandler) recordCompletion(tID TaskID, workStart time.Time, done
}
}
_, err = tx.Exec(`INSERT INTO harmony_task_history
(task_id, name, posted, work_start, work_end, result, err)
VALUES ($1, $2, $3, $4, $5, $6, $7)`, tID, h.Name, postedTime, workStart, workEnd, done, result)
(task_id, name, posted, work_start, work_end, result, by_host_and_port, err)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)`, tID, h.Name, postedTime, workStart, workEnd, done, h.TaskEngine.hostAndPort, result)
if err != nil {
return false, fmt.Errorf("could not write history: %w", err)
}