Add monitoring service and database schema
- Implement monitoring service with heartbeat, lease tasks, resume tasks, and task result handling. - Create monitoring time utilities for business date calculations. - Add unit tests for date window resolution and business day handling. - Define database schema for monitoring-related tables including quotas, daily reports, and task management. - Establish migration scripts for creating and dropping monitoring tables.
This commit is contained in:
@@ -288,6 +288,10 @@ func (s *MediaService) RegisterPluginInstallation(ctx context.Context, req Regis
|
||||
}
|
||||
}
|
||||
|
||||
if err := ensureMonitoringPrimaryInstallation(ctx, tx, actor.TenantID, installationID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := tx.Commit(ctx); err != nil {
|
||||
return nil, response.ErrInternal(50065, "installation_commit_failed", "failed to commit plugin installation")
|
||||
}
|
||||
@@ -300,6 +304,21 @@ func (s *MediaService) RegisterPluginInstallation(ctx context.Context, req Regis
|
||||
}, nil
|
||||
}
|
||||
|
||||
func ensureMonitoringPrimaryInstallation(ctx context.Context, tx pgx.Tx, tenantID, installationID int64) error {
|
||||
if _, err := tx.Exec(ctx, `
|
||||
INSERT INTO tenant_monitoring_quotas (
|
||||
tenant_id, primary_installation_id
|
||||
)
|
||||
VALUES ($1, $2)
|
||||
ON CONFLICT (tenant_id) DO UPDATE
|
||||
SET primary_installation_id = COALESCE(tenant_monitoring_quotas.primary_installation_id, EXCLUDED.primary_installation_id),
|
||||
updated_at = NOW()
|
||||
`, tenantID, installationID); err != nil {
|
||||
return response.ErrInternal(50068, "monitoring_quota_update_failed", "failed to assign monitoring plugin installation")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *MediaService) ListPlatformAccounts(ctx context.Context) ([]PlatformAccountResponse, error) {
|
||||
actor := auth.MustActor(ctx)
|
||||
rows, err := s.pool.Query(ctx, `
|
||||
|
||||
Reference in New Issue
Block a user