aboutsummaryrefslogtreecommitdiff
path: root/acid.go
diff options
context:
space:
mode:
Diffstat (limited to 'acid.go')
-rw-r--r--acid.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/acid.go b/acid.go
index 16322a5..edbe987 100644
--- a/acid.go
+++ b/acid.go
@@ -507,6 +507,28 @@ type GiteaPushEvent struct {
} `json:"repository"`
}
+func getPendingRunnersFor(ctx context.Context, tx *sql.Tx,
+ owner, repo, hash string) (map[string]struct{}, error) {
+ rows, err := tx.QueryContext(ctx, `SELECT DISTINCT runner FROM task
+ WHERE owner = ? AND repo = ? AND hash = ? AND state = ?`,
+ owner, repo, hash, taskStateNew)
+ if err != nil {
+ return nil, err
+ }
+ defer rows.Close()
+
+ runners := make(map[string]struct{})
+ for rows.Next() {
+ var r string
+ err := rows.Scan(&r)
+ if err != nil {
+ return nil, err
+ }
+ runners[r] = struct{}{}
+ }
+ return runners, rows.Err()
+}
+
func createTasks(ctx context.Context,
owner, repo, hash string, runners []string) error {
tx, err := gDB.BeginTx(ctx, nil)
@@ -515,6 +537,16 @@ func createTasks(ctx context.Context,
}
defer tx.Rollback()
+ // When you push a tag for a commit that has already had its task run,
+ // running it anew may make it receive a new "git describe" value.
+ //
+ // But if the task hasn't managed to run yet and is currently
+ // still enqueued, duplicating it provides nothing.
+ pending, err := getPendingRunnersFor(ctx, tx, owner, repo, hash)
+ if err != nil {
+ return err
+ }
+
stmt, err := tx.Prepare(
`INSERT INTO task(owner, repo, hash, runner, created, changed)
VALUES (?, ?, ?, ?, unixepoch('now'), unixepoch('now'))`)
@@ -523,6 +555,9 @@ func createTasks(ctx context.Context,
}
for _, runner := range runners {
+ if _, ok := pending[runner]; ok {
+ continue
+ }
if _, err := stmt.Exec(owner, repo, hash, runner); err != nil {
return err
}