(ctx context.Context, idx int, url string)
| 144 | } |
| 145 | |
| 146 | func (c *Client) fetchScriptStats(ctx context.Context, idx int, url string) { |
| 147 | reqCtx, cancel := context.WithTimeout(ctx, scriptStatsRequestTimeout) |
| 148 | defer cancel() |
| 149 | req, err := http.NewRequestWithContext(reqCtx, http.MethodGet, url, nil) |
| 150 | if err != nil { |
| 151 | return |
| 152 | } |
| 153 | resp, err := c.pickHTTPClient().Do(req) |
| 154 | if err != nil { |
| 155 | // Transport error — don't bump the daily count (request never reached |
| 156 | // Apps Script) and don't log; the next interval will retry. |
| 157 | return |
| 158 | } |
| 159 | defer resp.Body.Close() |
| 160 | |
| 161 | body, readErr := io.ReadAll(io.LimitReader(resp.Body, scriptStatsMaxBody)) |
| 162 | // doGet, like doPost, consumes one Apps Script invocation regardless of |
| 163 | // what we do with the response, so bump the daily counter on any HTTP |
| 164 | // response we got back. |
| 165 | c.bumpDailyCount(idx) |
| 166 | if readErr != nil { |
| 167 | return |
| 168 | } |
| 169 | |
| 170 | if resp.StatusCode != http.StatusOK { |
| 171 | return |
| 172 | } |
| 173 | c.recordScriptStatsFromBody(idx, url, body) |
| 174 | } |
| 175 | |
| 176 | // recordScriptStatsFromBody parses a doGet response body and stores the count. |
| 177 | // Split out from fetchScriptStats so the parsing logic is unit-testable without |
no test coverage detected