ensure that reps cannot be assigned agent, this should be done manually by organizing leads in ST
This commit is contained in:
parent
d666849759
commit
ede7884b31
2 changed files with 39 additions and 5 deletions
42
reconcile.go
42
reconcile.go
|
|
@ -26,11 +26,45 @@ func (s *Server) reconcile(ctx context.Context, runID int64, rep *User, dept str
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
assigned, skipped := 0, 0
|
// loop
|
||||||
for _, m := range members {
|
assigned, skipped, failed := 0, 0, 0
|
||||||
// ... ActiveAgent check, AssignAgent or skip
|
|
||||||
}
|
|
||||||
|
|
||||||
|
for _, m := range members {
|
||||||
|
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
log.Printf("run %d: cancelled after %d assigned, %d skipped", runID, assigned, skipped)
|
||||||
|
return ctx.Err()
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
|
||||||
|
existing, err := client.ActiveAgent(ctx, m)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("run %d: checking agent for %d failed: %v", runID, m, err)
|
||||||
|
failed++
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if existing != 0 {
|
||||||
|
// Fill-only: never displace an existing agent.
|
||||||
|
skipped++
|
||||||
|
if err := s.store.LogSkip(runID, m, existing, agent); err != nil {
|
||||||
|
log.Printf("run %d: logging skip for %d failed: %v", runID, m, err)
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := client.AssignAgent(ctx, m, agent); err != nil {
|
||||||
|
log.Printf("run %d: assigning %d to %d failed: %v", runID, m, agent, err)
|
||||||
|
failed++
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
assigned++
|
||||||
|
|
||||||
|
if err := s.store.SetProgress(runID, m); err != nil {
|
||||||
|
log.Printf("run %d: recording progress failed: %v", runID, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
if assigned == 0 && skipped > 0 {
|
if assigned == 0 && skipped > 0 {
|
||||||
log.Printf("WARNING: run %d: assigned nobody; all %d members already have agents",
|
log.Printf("WARNING: run %d: assigned nobody; all %d members already have agents",
|
||||||
runID, skipped)
|
runID, skipped)
|
||||||
|
|
|
||||||
2
store.go
2
store.go
|
|
@ -67,7 +67,7 @@ func (s *SQLStore) RepsFor(chapterID int64, dept string) ([]int64, error) {
|
||||||
|
|
||||||
func (s *SQLStore) EligibleMembers(chapterID int64, dept string) ([]int64, error) {
|
func (s *SQLStore) EligibleMembers(chapterID int64, dept string) ([]int64, error) {
|
||||||
return s.userIDs(`SELECT id FROM people
|
return s.userIDs(`SELECT id FROM people
|
||||||
WHERE is_eligible = 1 AND chapter_id = ? AND department = ?
|
WHERE is_eligible = 1 AND is_rep = 0 AND chapter_id = ? AND department = ?
|
||||||
ORDER BY id`, chapterID, dept)
|
ORDER BY id`, chapterID, dept)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue