~james/core

core/migrator/db/models.go -rw-r--r-- 1.5 KiB
452f17b7 — james chore(import): snapshot james.dad.town/core at f70c71c7696a 17 hours ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package db

import (
	"time"
)

type JobStatus string

const (
	StatusQueued                JobStatus = "queued"
	StatusCloning               JobStatus = "cloning"
	StatusImporting             JobStatus = "importing"
	StatusCompleted             JobStatus = "completed"
	StatusFailed                JobStatus = "failed"
	StatusAuthorizationRequired JobStatus = "authorization_required"
)

func (s JobStatus) IsTerminal() bool {
	return s == StatusCompleted || s == StatusFailed || s == StatusAuthorizationRequired
}

func (s JobStatus) CanRetry() bool {
	return s == StatusFailed || s == StatusAuthorizationRequired
}

type Batch struct {
	ID                  string
	OwnerDid            string
	RequestID           string
	RequestDigest       string
	EncryptedToken      *string
	CredentialExpiresAt *time.Time
	CreatedAt           time.Time
	UpdatedAt           time.Time
}

type Job struct {
	ID              int64
	BatchID         string
	RepoDid         string
	Name            string
	KnotDid         string
	SourceURL       string
	Description     string
	Private         bool
	CapabilityToken *string
	Status          JobStatus
	Attempts        int
	NextAttemptAt   time.Time
	Error           *string
	CreatedAt       time.Time
	UpdatedAt       time.Time
}

type Task struct {
	ID        string
	OwnerDid  string
	CreatedAt time.Time
	UpdatedAt time.Time
	Jobs      []Job
}

func (b *Batch) Task(jobs []Job) Task {
	return Task{
		ID:        b.ID,
		OwnerDid:  b.OwnerDid,
		CreatedAt: b.CreatedAt,
		UpdatedAt: b.UpdatedAt,
		Jobs:      jobs,
	}
}