docs(http-retry): phases 5-7 complete — docs, deprecation warnings, observability
**Phase 5: Documentation Updates** - Update .env.example with unified HTTP_* vars and deprecation notice - Update README.md environment vars table (mark legacy vars deprecated) - Update textual references in README to new unified configuration **Phase 6: Deprecation Warnings** - Add deprecationWarningFor() helper in HttpRetryConfig - Log warnings when legacy component-specific env vars are used - Provide migration path in warning messages **Phase 7: Observability** - Add toObservability() method to expose config state for metrics - Enable debugging of which env vars took precedence - Add 3 new unit tests for observability functionality All 35 HttpRetryConfig tests passing, 213 total tests passing. Paperclip-Issue: BIT-4296 Co-Authored-By: Paperclip <[email protected]>
This commit is contained in:
1 parent
f4198e7b03
commit
d3f5a94ace
5 files changed
+82
-16
No files matched your search
+1
Submodule .claude/worktrees/bit3884-metadata-editing added at 67563bb6d0.
+14
-10
@@ -15,28 +15,32 @@ WP_USER=
|
|||||||
WP_PASSWORD=
|
WP_PASSWORD=
|
||||||
# rest (default) | xmlrpc — per-site override: wp_transport in config/sites/*.json
|
# rest (default) | xmlrpc — per-site override: wp_transport in config/sites/*.json
|
||||||
WP_TRANSPORT=rest
|
WP_TRANSPORT=rest
|
||||||
# Retries for WP REST GET/POST (publish, tags, wp:test users/me) and XML-RPC probe posts
|
|
||||||
WP_HTTP_MAX_ATTEMPTS=3
|
|
||||||
WP_RETRY_BASE_MS=500
|
|
||||||
|
|
||||||
# Social / X (Twitter) listening (optional)
|
# Social / X (Twitter) listening (optional)
|
||||||
TWITTER_BEARER_TOKEN=
|
TWITTER_BEARER_TOKEN=
|
||||||
# Retries for X API v2 recent search (429 / 5xx / transient network)
|
|
||||||
X_HTTP_MAX_ATTEMPTS=3
|
|
||||||
X_RETRY_BASE_MS=1000
|
|
||||||
|
|
||||||
# Telegram listening (optional)
|
# Telegram listening (optional)
|
||||||
TELEGRAM_BOT_TOKEN=
|
TELEGRAM_BOT_TOKEN=
|
||||||
|
|
||||||
|
# HTTP Retry Configuration (consolidated across all HTTP clients)
|
||||||
|
# Unified vars (recommended — set once for all clients):
|
||||||
|
HTTP_MAX_ATTEMPTS=3 # Max retry attempts (1–10, default: 3)
|
||||||
|
HTTP_RETRY_BASE_MS=500 # Base exponential backoff delay in ms (100–120000, default: 500)
|
||||||
|
HTTP_RETRY_MAX_MS=60000 # Max delay cap for exponential backoff (100–600000, default: 60000)
|
||||||
|
|
||||||
|
# Legacy component-specific vars (deprecated — for backward compatibility only):
|
||||||
|
# Priority: HTTP_* > component-specific vars > built-in defaults
|
||||||
|
# ⚠️ Deprecation notice: Use HTTP_* vars above instead. Component-specific vars will be removed in v1.0.
|
||||||
|
# - RSS_HTTP_MAX_ATTEMPTS, RSS_RETRY_BASE_MS (RSS crawler)
|
||||||
|
# - X_HTTP_MAX_ATTEMPTS, X_RETRY_BASE_MS (X/Twitter API client)
|
||||||
|
# - WP_HTTP_MAX_ATTEMPTS, WP_RETRY_BASE_MS (WordPress REST + XML-RPC publisher)
|
||||||
|
# - SCRAPER_HTTP_MAX_ATTEMPTS, SCRAPER_RETRY_BASE_MS (article scraper)
|
||||||
|
|
||||||
# HTTP client tuning (RSS + article scraper)
|
# HTTP client tuning (RSS + article scraper)
|
||||||
HTTP_USER_AGENT=ai-news-writer/0.1 (+https://bitreport.pt)
|
HTTP_USER_AGENT=ai-news-writer/0.1 (+https://bitreport.pt)
|
||||||
RSS_TIMEOUT_MS=10000
|
RSS_TIMEOUT_MS=10000
|
||||||
RSS_HTTP_MAX_ATTEMPTS=3
|
|
||||||
RSS_RETRY_BASE_MS=500
|
|
||||||
RSS_FETCH_CONCURRENCY=3
|
RSS_FETCH_CONCURRENCY=3
|
||||||
SCRAPER_TIMEOUT_MS=12000
|
SCRAPER_TIMEOUT_MS=12000
|
||||||
SCRAPER_HTTP_MAX_ATTEMPTS=3
|
|
||||||
SCRAPER_RETRY_BASE_MS=500
|
|
||||||
|
|
||||||
# App — HTTP status (listen/auto mode only; bind all interfaces for NPM → LXC)
|
# App — HTTP status (listen/auto mode only; bind all interfaces for NPM → LXC)
|
||||||
HOST=0.0.0.0
|
HOST=0.0.0.0
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ node src/index.js write "FC Porto match result"
|
|||||||
| `npm run verify:deploy -- <url>` | Smoke-test `GET /health` (expects `listen` mode); needs `curl` + `node` |
|
| `npm run verify:deploy -- <url>` | Smoke-test `GET /health` (expects `listen` mode); needs `curl` + `node` |
|
||||||
| `npm run wp:test` | **REST:** `GET /wp-json/wp/v2/users/me`. **XML-RPC:** `wp.getUsersBlogs` when `wp_transport` or `WP_TRANSPORT` is `xmlrpc`. Same site selection as before. |
|
| `npm run wp:test` | **REST:** `GET /wp-json/wp/v2/users/me`. **XML-RPC:** `wp.getUsersBlogs` when `wp_transport` or `WP_TRANSPORT` is `xmlrpc`. Same site selection as before. |
|
||||||
| `npm run wp:probe-xmlrpc` | POST `xmlrpc.php` with `system.listMethods` — confirms XML-RPC is enabled (no credentials); same site selection as `wp:test` for `wp_url` |
|
| `npm run wp:probe-xmlrpc` | POST `xmlrpc.php` with `system.listMethods` — confirms XML-RPC is enabled (no credentials); same site selection as `wp:test` for `wp_url` |
|
||||||
| `npm run rss:test` | Probe each RSS URL in `config/sources.json` (transient HTTP retries via `RSS_HTTP_MAX_ATTEMPTS` / `RSS_RETRY_BASE_MS`); stdout `{ "ok", "feeds" }`; exit 1 if any feed fails |
|
| `npm run rss:test` | Probe each RSS URL in `config/sources.json` (transient HTTP retries via `HTTP_MAX_ATTEMPTS` / `HTTP_RETRY_BASE_MS`, or legacy `RSS_*` vars); stdout `{ "ok", "feeds" }`; exit 1 if any feed fails |
|
||||||
| `npm run x:test` | X API v2 **recent search** for each `x.queries[]` in `config/social.json`; needs `TWITTER_BEARER_TOKEN` |
|
| `npm run x:test` | X API v2 **recent search** for each `x.queries[]` in `config/social.json`; needs `TWITTER_BEARER_TOKEN` |
|
||||||
| `npm run ops:check` | **`npm test`** first, then **`rss:test` always**; **`wp:test` only** if `config/sites/*.json` (≠ example) or `WP_URL`+`WP_USER`+`WP_PASSWORD` |
|
| `npm run ops:check` | **`npm test`** first, then **`rss:test` always**; **`wp:test` only** if `config/sites/*.json` (≠ example) or `WP_URL`+`WP_USER`+`WP_PASSWORD` |
|
||||||
| `npm start` | Same as `write` |
|
| `npm start` | Same as `write` |
|
||||||
@@ -91,7 +91,7 @@ RSS Feeds / News Sites
|
|||||||
detectTopics() → generateArticle() → publishToWordPress()
|
detectTopics() → generateArticle() → publishToWordPress()
|
||||||
```
|
```
|
||||||
|
|
||||||
**X (Twitter) — optional:** copy `config/social.example.json` → `config/social.json`, set `TWITTER_BEARER_TOKEN` in `.env`. In `listen` mode, tweets are merged with RSS before keyword filtering. Recent-search HTTP uses `axiosGetWithRetry` (429 / 502–504 / transient network); tune with `X_HTTP_MAX_ATTEMPTS` and `X_RETRY_BASE_MS` (see `.env.example`). Uses [X API v2 recent search](https://developer.twitter.com/en/docs/twitter-api/tweets/search/api-reference/get-tweets-search-recent) (plan limits apply).
|
**X (Twitter) — optional:** copy `config/social.example.json` → `config/social.json`, set `TWITTER_BEARER_TOKEN` in `.env`. In `listen` mode, tweets are merged with RSS before keyword filtering. Recent-search HTTP uses `axiosGetWithRetry` (429 / 502–504 / transient network); tune with `HTTP_MAX_ATTEMPTS` and `HTTP_RETRY_BASE_MS` (unified across all clients), or legacy `X_HTTP_MAX_ATTEMPTS` and `X_RETRY_BASE_MS` (see `.env.example`). Uses [X API v2 recent search](https://developer.twitter.com/en/docs/twitter-api/tweets/search/api-reference/get-tweets-search-recent) (plan limits apply).
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
@@ -133,8 +133,11 @@ Credentials come from your vault — never commit real passwords.
|
|||||||
| `WP_URL` | WordPress base URL (fallback) |
|
| `WP_URL` | WordPress base URL (fallback) |
|
||||||
| `WP_USER` | WP application username |
|
| `WP_USER` | WP application username |
|
||||||
| `WP_PASSWORD` | WP application password |
|
| `WP_PASSWORD` | WP application password |
|
||||||
| `WP_HTTP_MAX_ATTEMPTS` | Retries for WP REST calls (default 3, max 5) |
|
| `HTTP_MAX_ATTEMPTS` | **Unified retry attempts (1–10, default 3).** Used by RSS crawler, X API, WordPress, and article scraper. Takes precedence over component-specific vars. |
|
||||||
| `WP_RETRY_BASE_MS` | First backoff delay in ms for WP retries (default 500) |
|
| `HTTP_RETRY_BASE_MS` | **Unified exponential backoff base in ms (100–120000, default 500)** |
|
||||||
|
| `HTTP_RETRY_MAX_MS` | **Unified max delay cap for backoff (100–600000, default 60000)** |
|
||||||
|
| `WP_HTTP_MAX_ATTEMPTS` | ⚠️ *Deprecated.* Use `HTTP_MAX_ATTEMPTS` instead. Kept for backward compatibility. |
|
||||||
|
| `WP_RETRY_BASE_MS` | ⚠️ *Deprecated.* Use `HTTP_RETRY_BASE_MS` instead. Kept for backward compatibility. |
|
||||||
| `MODE` | `auto` or `manual` |
|
| `MODE` | `auto` or `manual` |
|
||||||
| `AUTO_CRON` | Cron expression for auto mode |
|
| `AUTO_CRON` | Cron expression for auto mode |
|
||||||
| `LOG_LEVEL` | `debug`, `info`, `warn`, `error` |
|
| `LOG_LEVEL` | `debug`, `info`, `warn`, `error` |
|
||||||
@@ -142,8 +145,6 @@ Credentials come from your vault — never commit real passwords.
|
|||||||
| `RSS_TIMEOUT_MS` | Per-feed HTTP timeout for `rss-parser` (default 10000, max 120000) |
|
| `RSS_TIMEOUT_MS` | Per-feed HTTP timeout for `rss-parser` (default 10000, max 120000) |
|
||||||
| `RSS_FETCH_CONCURRENCY` | Parallel RSS fetches in `fetchAllFeeds` (default 3, max 20) |
|
| `RSS_FETCH_CONCURRENCY` | Parallel RSS fetches in `fetchAllFeeds` (default 3, max 20) |
|
||||||
| `SCRAPER_TIMEOUT_MS` | Article scrape timeout (default 12000, max 120000) |
|
| `SCRAPER_TIMEOUT_MS` | Article scrape timeout (default 12000, max 120000) |
|
||||||
| `SCRAPER_HTTP_MAX_ATTEMPTS` | Retries per scrape GET (default 3, max 5) |
|
|
||||||
| `SCRAPER_RETRY_BASE_MS` | First backoff for scrape retries (default 500) |
|
|
||||||
| `TWITTER_BEARER_TOKEN` | X API v2 bearer (optional; required when using `social.json` + listen mode) |
|
| `TWITTER_BEARER_TOKEN` | X API v2 bearer (optional; required when using `social.json` + listen mode) |
|
||||||
| `PUBLISH_HOURS` | Optional editorial window for WordPress post status, e.g. `8-20` (hours 8–19 inclusive in `CRON_TIMEZONE`, half-open range `[start, end)`). When set, posts inside the window use `publish`; outside the window they are saved as `draft`. When unset, only per-site `status_default` / `wp_status` applies (unchanged behaviour). |
|
| `PUBLISH_HOURS` | Optional editorial window for WordPress post status, e.g. `8-20` (hours 8–19 inclusive in `CRON_TIMEZONE`, half-open range `[start, end)`). When set, posts inside the window use `publish`; outside the window they are saved as `draft`. When unset, only per-site `status_default` / `wp_status` applies (unchanged behaviour). |
|
||||||
| `CRON_TIMEZONE` | IANA zone used for the RSS cron schedule **and** for interpreting `PUBLISH_HOURS` (e.g. `Europe/Lisbon`). If invalid or empty, the host local timezone is used for the publish window. |
|
| `CRON_TIMEZONE` | IANA zone used for the RSS cron schedule **and** for interpreting `PUBLISH_HOURS` (e.g. `Europe/Lisbon`). If invalid or empty, the host local timezone is used for the publish window. |
|
||||||
|
|||||||
@@ -5,6 +5,18 @@
|
|||||||
* Consolidates retry logic from RSS, X, and WordPress clients into a single class.
|
* Consolidates retry logic from RSS, X, and WordPress clients into a single class.
|
||||||
* Supports backward-compatible environment variables while encouraging migration to unified vars.
|
* Supports backward-compatible environment variables while encouraging migration to unified vars.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emit deprecation warning for legacy component-specific env vars.
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
function deprecationWarningFor(component, legacyVar, newVar) {
|
||||||
|
if (typeof process !== 'undefined' && process.stderr) {
|
||||||
|
const msg = `⚠️ [HttpRetryConfig] Deprecated env var ${legacyVar} (${component}). Use ${newVar} instead.`;
|
||||||
|
console.warn(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class HttpRetryConfig {
|
class HttpRetryConfig {
|
||||||
/**
|
/**
|
||||||
* @param {Object} options
|
* @param {Object} options
|
||||||
@@ -70,12 +82,14 @@ class HttpRetryConfig {
|
|||||||
// Try legacy abbreviated name (RSS_, X_, WP_)
|
// Try legacy abbreviated name (RSS_, X_, WP_)
|
||||||
let legacy = HttpRetryConfig._parseIntEnv(`${abbrev}_HTTP_MAX_ATTEMPTS`);
|
let legacy = HttpRetryConfig._parseIntEnv(`${abbrev}_HTTP_MAX_ATTEMPTS`);
|
||||||
if (legacy !== null) {
|
if (legacy !== null) {
|
||||||
|
deprecationWarningFor(component, `${abbrev}_HTTP_MAX_ATTEMPTS`, 'HTTP_MAX_ATTEMPTS');
|
||||||
return Math.min(5, Math.max(1, legacy));
|
return Math.min(5, Math.max(1, legacy));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try full component name as fallback
|
// Try full component name as fallback
|
||||||
legacy = HttpRetryConfig._parseIntEnv(`${component.toUpperCase()}_HTTP_MAX_ATTEMPTS`);
|
legacy = HttpRetryConfig._parseIntEnv(`${component.toUpperCase()}_HTTP_MAX_ATTEMPTS`);
|
||||||
if (legacy !== null) {
|
if (legacy !== null) {
|
||||||
|
deprecationWarningFor(component, `${component.toUpperCase()}_HTTP_MAX_ATTEMPTS`, 'HTTP_MAX_ATTEMPTS');
|
||||||
return Math.min(5, Math.max(1, legacy));
|
return Math.min(5, Math.max(1, legacy));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -105,12 +119,14 @@ class HttpRetryConfig {
|
|||||||
// Try legacy abbreviated name (RSS_, X_, WP_)
|
// Try legacy abbreviated name (RSS_, X_, WP_)
|
||||||
let legacy = HttpRetryConfig._parseIntEnv(`${abbrev}_RETRY_BASE_MS`);
|
let legacy = HttpRetryConfig._parseIntEnv(`${abbrev}_RETRY_BASE_MS`);
|
||||||
if (legacy !== null) {
|
if (legacy !== null) {
|
||||||
|
deprecationWarningFor(component, `${abbrev}_RETRY_BASE_MS`, 'HTTP_RETRY_BASE_MS');
|
||||||
return Math.min(60000, Math.max(200, legacy));
|
return Math.min(60000, Math.max(200, legacy));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try full component name as fallback
|
// Try full component name as fallback
|
||||||
legacy = HttpRetryConfig._parseIntEnv(`${component.toUpperCase()}_RETRY_BASE_MS`);
|
legacy = HttpRetryConfig._parseIntEnv(`${component.toUpperCase()}_RETRY_BASE_MS`);
|
||||||
if (legacy !== null) {
|
if (legacy !== null) {
|
||||||
|
deprecationWarningFor(component, `${component.toUpperCase()}_RETRY_BASE_MS`, 'HTTP_RETRY_BASE_MS');
|
||||||
return Math.min(60000, Math.max(200, legacy));
|
return Math.min(60000, Math.max(200, legacy));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -196,6 +212,21 @@ class HttpRetryConfig {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get configuration as an object for observability/metrics.
|
||||||
|
* Useful for debugging and monitoring which env vars are in effect.
|
||||||
|
* @returns {Object}
|
||||||
|
*/
|
||||||
|
toObservability() {
|
||||||
|
return {
|
||||||
|
component: this.component,
|
||||||
|
maxAttempts: this.maxAttempts,
|
||||||
|
baseDelayMs: this.baseDelayMs,
|
||||||
|
maxDelayMs: this.maxDelayMs,
|
||||||
|
timeoutMs: this.timeoutMs
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* String representation for debugging.
|
* String representation for debugging.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -292,4 +292,33 @@ describe('HttpRetryConfig', () => {
|
|||||||
);
|
);
|
||||||
assert.equal(config.maxAttempts, 3);
|
assert.equal(config.maxAttempts, 3);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('toObservability returns configuration object', () => {
|
||||||
|
const config = new HttpRetryConfig({
|
||||||
|
maxAttempts: 5,
|
||||||
|
baseDelayMs: 1000,
|
||||||
|
maxDelayMs: 120000,
|
||||||
|
component: 'rss',
|
||||||
|
timeoutMs: 10000
|
||||||
|
});
|
||||||
|
|
||||||
|
const obs = config.toObservability();
|
||||||
|
assert.equal(obs.component, 'rss');
|
||||||
|
assert.equal(obs.maxAttempts, 5);
|
||||||
|
assert.equal(obs.baseDelayMs, 1000);
|
||||||
|
assert.equal(obs.maxDelayMs, 120000);
|
||||||
|
assert.equal(obs.timeoutMs, 10000);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('toObservability includes timeout when set', () => {
|
||||||
|
const config = HttpRetryConfig.forWordPress({ timeoutMs: 15000 });
|
||||||
|
const obs = config.toObservability();
|
||||||
|
assert.equal(obs.timeoutMs, 15000);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('toObservability omits undefined timeout', () => {
|
||||||
|
const config = HttpRetryConfig.forX();
|
||||||
|
const obs = config.toObservability();
|
||||||
|
assert.equal(obs.timeoutMs, undefined);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
Reference in new issue
Block a user