oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package library
2
3import "gorm.io/gorm"
4
5func ExecutionSpecialist(tx *gorm.DB, key string, unavailable error, normalize func(error) error) (Specialist, error) {
6 var sp Specialist
7 if err := tx.Where("key = ?", key).First(&sp).Error; err != nil {
8 return sp, normalize(err)
9 }
10 if sp.Archived || sp.MaxConcurrent <= 0 {
11 return sp, unavailable
12 }
13 // Containment-pending attempts occupy capacity even after stop is requested.
14 capabilities := []string{key}
15 if key == "engineering" {
16 capabilities = []string{"reproduce", "implement", "reconcile"}
17 }
18 if key == "review" {
19 capabilities = []string{"review", "verify"}
20 }
21 var live int64
22 if key == "product" {
23 capabilities = []string{"scope", "research"}
24 }
25 if err := tx.Table("attempts").Joins("JOIN steps ON steps.id = attempts.step_id").Where("attempts.containment = ? AND (steps.capability IN ? OR EXISTS (SELECT 1 FROM runner_assignments ra WHERE ra.attempt_id=attempts.id AND json_extract(ra.brief,'$.step.SpecialistKey')=?))", "pending", capabilities, key).Count(&live).Error; err != nil {
26 return sp, normalize(err)
27 }
28 if live >= int64(sp.MaxConcurrent) {
29 return sp, unavailable
30 }
31 return sp, nil
32}
33