CountActiveInstances counts the number of instances.
(ctx context.Context, workspaceID string)
| 10 | |
| 11 | // CountActiveInstances counts the number of instances. |
| 12 | func (s *Store) CountActiveInstances(ctx context.Context, workspaceID string) (int, error) { |
| 13 | q := qb.Q().Space("SELECT count(1) FROM instance WHERE instance.workspace = ?", workspaceID).And("instance.deleted = ?", false) |
| 14 | |
| 15 | query, args, err := q.ToSQL() |
| 16 | if err != nil { |
| 17 | return 0, errors.Wrapf(err, "failed to build sql") |
| 18 | } |
| 19 | |
| 20 | var count int |
| 21 | if err := s.GetDB().QueryRowContext(ctx, query, args...).Scan(&count); err != nil { |
| 22 | return 0, err |
| 23 | } |
| 24 | return count, nil |
| 25 | } |
| 26 | |
| 27 | // CountActivePrincipals counts non-deleted principals cross-workspace. Used for display purposes |
| 28 | // (e.g. actuator info) — not for seat limit enforcement. |