Hub 2.7.1: one click is one update

Buttons are off from the click until the Hub answers (the Updates page and
every action on an install's page); the server refuses a second update for
an install with one planned or running (ALREADY_PLANNED). Test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-19 22:15:58 +02:00
co-authored by Claude Opus 5.5
parent 90fdde054a
commit dab6fbcff6
9 changed files with 81 additions and 21 deletions
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "events-hub-backend",
"version": "2.7.0",
"version": "2.7.1",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "events-hub-backend",
"version": "2.7.0",
"version": "2.7.1",
"hasInstallScript": true,
"dependencies": {
"@anthropic-ai/sdk": "^1.3.0",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "events-hub-backend",
"version": "2.7.0",
"version": "2.7.1",
"private": true,
"description": "Cross Events Hub — API for managing Cross Events installs, licences and heartbeats",
"main": "src/index.js",
+3
View File
@@ -757,6 +757,9 @@ async function scheduleUpdate({ deploymentIds, product: wanted = null, version,
}
for (const d of deployments) {
if (d.status !== 'live') throw fail(409, 'NOT_LIVE', `${d.shortName} isn't live (${d.status}).`);
// 2.7.1: one update at a time per install, so a second click (or a second tab) can't plan another.
const pending = await prisma.job.findFirst({ where: { deploymentId: d.id, type: 'deploy', status: { in: ['scheduled', 'queued', 'delivered'] } } });
if (pending) throw fail(409, 'ALREADY_PLANNED', `${d.shortName} already has an update ${pending.status === 'delivered' ? 'running' : `planned for ${sast(pending.notBefore)}`}. Cancel it first (its job) to plan another.`);
if (d.server.removedAt) throw fail(409, 'SERVER_REMOVED', `${d.shortName}'s server was removed.`);
if (d.install) {
// Accounts is handled below (kept, updated, or installed first); anything else must be met.
+13
View File
@@ -730,3 +730,16 @@ describe('emergency updates as soon as possible, and events on now (2.7.0)', ()
expect((await urgent([stale.id, older.id], { asap: true })).jobs).toHaveLength(2);
});
});
describe('one update at a time per install (2.7.1)', () => {
test('a second update for an install with one planned is refused, and none is made', async () => {
const { server } = await joinServer();
await servers.setServerConfig(server.id, { TRUST_PROXY: 'loopback' });
await db.install.create({ data: { id: 'inst-twice', customerId: 'cust-1', product: 'events', name: 'Twice', url: 'https://events.twice.co.za', secret: 'x', version: '2.3.0' } });
const d = await db.deployment.create({ data: { id: 'dep-twice', serverId: server.id, customerId: 'cust-1', installId: 'inst-twice', product: 'events', shortName: 'twice', domain: 'events.twice.co.za', webPort: 24000, apiPort: 24001, status: 'live' } });
const at = new Date(NOW.getTime() + 5 * 3600e3);
await jobs.scheduleUpdate({ deploymentIds: [d.id], version: '2.4.0', at }, admin, NOW);
await expect(jobs.scheduleUpdate({ deploymentIds: [d.id], version: '2.4.0', at }, admin, NOW)).rejects.toMatchObject({ code: 'ALREADY_PLANNED' });
expect(await db.job.count({ where: { deploymentId: d.id, type: 'deploy' } })).toBe(1);
});
});