Worker deploys from CI, with version reporting (#40)
CI / Lint (eslint) (push) Successful in 14s
CI / Test (jest) (push) Successful in 18s
CI / Security (npm audit) (push) Successful in 12s
CI / Integration (api) (push) Successful in 1m14s
CI / Scan (secrets, workflows, shell) (push) Successful in 1m29s
CI / Lint (eslint) (pull_request) Successful in 19s
CI / Test (jest) (pull_request) Successful in 13s
CI / Security (npm audit) (pull_request) Successful in 7s
CI / UI (playwright) (push) Successful in 1m43s
CI / Deploy (push) Skipped
CI / Deploy worker (push) Skipped
CI / Notify (push) Skipped
CI / Integration (api) (pull_request) Successful in 1m51s
CI / Scan (secrets, workflows, shell) (pull_request) Successful in 2m20s
CI / UI (playwright) (pull_request) Successful in 1m37s
CI / Deploy (pull_request) Skipped
CI / Deploy worker (pull_request) Skipped
CI / Notify (pull_request) Skipped
CI / Lint (eslint) (push) Successful in 14s
CI / Test (jest) (push) Successful in 18s
CI / Security (npm audit) (push) Successful in 12s
CI / Integration (api) (push) Successful in 1m14s
CI / Scan (secrets, workflows, shell) (push) Successful in 1m29s
CI / Lint (eslint) (pull_request) Successful in 19s
CI / Test (jest) (pull_request) Successful in 13s
CI / Security (npm audit) (pull_request) Successful in 7s
CI / UI (playwright) (push) Successful in 1m43s
CI / Deploy (push) Skipped
CI / Deploy worker (push) Skipped
CI / Notify (push) Skipped
CI / Integration (api) (pull_request) Successful in 1m51s
CI / Scan (secrets, workflows, shell) (pull_request) Successful in 2m20s
CI / UI (playwright) (pull_request) Successful in 1m37s
CI / Deploy (pull_request) Skipped
CI / Deploy worker (pull_request) Skipped
CI / Notify (pull_request) Skipped
- The worker reports its commit (VERSION file, or git rev-parse in a checkout) in worker_connect and heartbeat metadata. The server keeps it per live socket and /healthz lists worker_versions. - deploy/pulse_worker_deploy.sh <sha> <ts>, for the webhook on a worker host: replay and age checks, commit must be on main, installs worker.js and the npm manifests from exactly that commit, writes VERSION, npm ci, restarts, waits until /healthz lists the sha, else restores the previous files. Sandbox tests cover deploy, replay, stale and malformed input, off-main commits, no-op redeploys and rollback. - New CI job Deploy worker after Deploy: only when worker/ or the npm manifests changed since the commit the workers report, so unrelated merges don't restart the worker; then waits for the worker to reconnect on the new commit. - README: Worker deploys (install, hook definition, adding a worker host). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4f6672a7ef
commit
ea939d4430
9 files changed
+439
-10
No files matched your search
+25
-3
@@ -8,6 +8,24 @@ require('dotenv').config();
|
||||
|
||||
const execAsync = promisify(exec);
|
||||
|
||||
// The commit this worker runs (#40): the VERSION file written by
|
||||
// deploy/pulse_worker_deploy.sh, or the git checkout it runs from.
|
||||
function detectVersion(dir = __dirname) {
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
try {
|
||||
const v = fs.readFileSync(path.join(dir, 'VERSION'), 'utf8').trim();
|
||||
if (/^[0-9a-f]{40}$/.test(v)) return v;
|
||||
} catch { /* no VERSION file */ }
|
||||
try {
|
||||
return require('child_process')
|
||||
.execFileSync('git', ['rev-parse', 'HEAD'], { cwd: dir, timeout: 5000, stdio: ['ignore', 'pipe', 'ignore'] })
|
||||
.toString().trim();
|
||||
} catch {
|
||||
return 'unknown';
|
||||
}
|
||||
}
|
||||
|
||||
class PulseWorker {
|
||||
constructor() {
|
||||
this.workerId = crypto.randomUUID();
|
||||
@@ -17,6 +35,7 @@ class PulseWorker {
|
||||
this.apiKey = process.env.WORKER_API_KEY;
|
||||
this.heartbeatInterval = parseInt(process.env.HEARTBEAT_INTERVAL || '30') * 1000;
|
||||
this.maxConcurrentTasks = parseInt(process.env.MAX_CONCURRENT_TASKS || '5');
|
||||
this.version = detectVersion();
|
||||
this.activeTasks = 0;
|
||||
this.ws = null;
|
||||
this.heartbeatTimer = null;
|
||||
@@ -25,6 +44,7 @@ class PulseWorker {
|
||||
async start() {
|
||||
console.log(`[PULSE Worker] Starting worker: ${this.workerName}`);
|
||||
console.log(`[PULSE Worker] Worker ID: ${this.workerId}`);
|
||||
console.log(`[PULSE Worker] Version: ${this.version}`);
|
||||
console.log(`[PULSE Worker] Server: ${this.serverUrl}`);
|
||||
|
||||
// Send initial heartbeat
|
||||
@@ -60,7 +80,8 @@ class PulseWorker {
|
||||
uptime: os.uptime(),
|
||||
loadavg: os.loadavg(),
|
||||
activeTasks: this.activeTasks,
|
||||
maxConcurrentTasks: this.maxConcurrentTasks
|
||||
maxConcurrentTasks: this.maxConcurrentTasks,
|
||||
version: this.version
|
||||
};
|
||||
|
||||
try {
|
||||
@@ -101,7 +122,8 @@ class PulseWorker {
|
||||
type: 'worker_connect',
|
||||
worker_id: this.workerId,
|
||||
worker_name: this.workerName,
|
||||
api_key: this.apiKey
|
||||
api_key: this.apiKey,
|
||||
version: this.version
|
||||
}));
|
||||
});
|
||||
|
||||
@@ -256,7 +278,7 @@ class PulseWorker {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { PulseWorker };
|
||||
module.exports = { PulseWorker, detectVersion };
|
||||
|
||||
// Start only when run directly (node worker.js), so tests can load the class.
|
||||
if (require.main === module) {
|
||||
|
||||
Reference in new issue
Block a user