"use strict"; function schedulerJobBelongsToServer(job, canonicalServer, serverId) { return serverId != null && job?.data?.serverId != null && String(job.data.serverId) === String(serverId) && String(job.data.serverName || "").toLowerCase() === canonicalServer.toLowerCase(); } async function resolveSchedulerRepeatablesForServer(queue, templates, canonicalServer, serverId) { if (serverId == null) return []; const canonicalKey = canonicalServer.toLowerCase(); const results = await Promise.all(templates.map(async (template) => { let definition; try { definition = JSON.parse(template.name || "{}"); } catch { return null; } if (String(definition?.serverName || "").toLowerCase() !== canonicalKey) return null; const { serverId: boundId, ...scheduleDefinition } = definition; if (boundId != null) { return { template, definition: scheduleDefinition, owned: String(boundId) === String(serverId) }; } // adpanel:scheduler-server-identity-bind - legacy templates need proof from their current occurrence. const next = Number(template.next); let owned = null; if (Number.isSafeInteger(next) && next > 0) { const repeat = await queue.repeat; const occurrenceId = repeat.getRepeatJobKey(template.name, next, template.key, null); const occurrence = await queue.getJob(occurrenceId); const repeatKey = occurrence?.repeatJobKey || occurrence?.opts?.repeat?.key; if (repeatKey === template.key && Number(occurrence?.opts?.prevMillis) === next && occurrence?.data?.serverId != null) { owned = schedulerJobBelongsToServer(occurrence, canonicalServer, serverId); } } return { template, definition: scheduleDefinition, owned }; })); return results.filter(Boolean); } module.exports = { schedulerJobBelongsToServer, resolveSchedulerRepeatablesForServer };