fetchServiceBannerLoop fetches the service banner on an interval. It will not be fetched immediately; the expectation is that it is primed elsewhere (and must be done before the session actually starts).
(ctx context.Context, aAPI proto.DRPCAgentClient28)
| 1035 | // not be fetched immediately; the expectation is that it is primed elsewhere |
| 1036 | // (and must be done before the session actually starts). |
| 1037 | func (a *agent) fetchServiceBannerLoop(ctx context.Context, aAPI proto.DRPCAgentClient28) error { |
| 1038 | ticker := time.NewTicker(a.announcementBannersRefreshInterval) |
| 1039 | defer ticker.Stop() |
| 1040 | for { |
| 1041 | select { |
| 1042 | case <-ctx.Done(): |
| 1043 | return ctx.Err() |
| 1044 | case <-ticker.C: |
| 1045 | bannersProto, err := aAPI.GetAnnouncementBanners(ctx, &proto.GetAnnouncementBannersRequest{}) |
| 1046 | if err != nil { |
| 1047 | if ctx.Err() != nil { |
| 1048 | return ctx.Err() |
| 1049 | } |
| 1050 | a.logger.Error(ctx, "failed to update notification banners", slog.Error(err)) |
| 1051 | return err |
| 1052 | } |
| 1053 | banners := make([]codersdk.BannerConfig, 0, len(bannersProto.AnnouncementBanners)) |
| 1054 | for _, bannerProto := range bannersProto.AnnouncementBanners { |
| 1055 | banners = append(banners, agentsdk.BannerConfigFromProto(bannerProto)) |
| 1056 | } |
| 1057 | a.announcementBanners.Store(&banners) |
| 1058 | } |
| 1059 | } |
| 1060 | } |
| 1061 | |
| 1062 | func (a *agent) run() (retErr error) { |
| 1063 | // This allows the agent to refresh its token if necessary. |
nothing calls this directly
no test coverage detected