- Events and Accounts: Background jobs are switched on or off and rescheduled from the admin; the choice is kept in the database (job_overrides), wins over the .env and applies at once. Accounts gets an Admin -> Background jobs page and per-job env flags, as Events. - Accounts: every email styled as Cross Events' (church colour, logo, button, footer), same plain text (src/lib/emails.ts). - Contracts 1.12.0: env-read / env-set agent jobs, envReadResultSchema, isSecretEnvName. - crosscode script: `crosscode env <church> <product>` reads the .env (secrets hidden) and, with --set/--unset/--restart, changes one file, rebuilds the frontend when its file changed, reloads, and puts the file back if the site doesn't answer (lib/envedit.cjs, tests/envedit.bats). - Agent 1.3.0: runs env-read and env-set. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
53 lines
2.0 KiB
JavaScript
53 lines
2.0 KiB
JavaScript
const prisma = require('../config/db');
|
|
const { safeErrorMessage } = require('../utils/errorUtils');
|
|
const { logAdminAction } = require('../utils/adminAudit');
|
|
const { getClientIp } = require('../utils/requestUtils');
|
|
const jobs = require('../jobs');
|
|
|
|
// @desc Background jobs: schedule, next run and the last 10 runs of each
|
|
// @route GET /api/admin/jobs
|
|
// @access Private/Admin
|
|
const listJobs = async (req, res) => {
|
|
try {
|
|
res.json(await jobs.jobStatus(prisma));
|
|
} catch (error) {
|
|
res.status(500).json({ message: safeErrorMessage(error) });
|
|
}
|
|
};
|
|
|
|
// @desc Run a background job now
|
|
// @route POST /api/admin/jobs/:name/run
|
|
// @access Private/Admin
|
|
const runJobNow = async (req, res) => {
|
|
try {
|
|
const result = await jobs.runNow(req.params.name);
|
|
logAdminAction({
|
|
actorId: req.user.id, actorRole: req.user.role, action: 'job_run_manual',
|
|
targetType: 'Job', targetId: req.params.name, metadata: { queued: result.queued }, ip: getClientIp(req),
|
|
});
|
|
res.json(result);
|
|
} catch (error) {
|
|
res.status(error.statusCode || 500).json({ message: safeErrorMessage(error) });
|
|
}
|
|
};
|
|
|
|
// @desc Switch a background job on or off, or change its schedule (3.4.0). Wins over the .env;
|
|
// null for either goes back to the .env.
|
|
// @route PUT /api/admin/jobs/:name
|
|
// @access Private/Admin
|
|
const updateJob = async (req, res) => {
|
|
try {
|
|
const body = req.body || {};
|
|
const choice = await jobs.setOverride(req.params.name, { enabled: body.enabled, cron: body.cron });
|
|
logAdminAction({
|
|
actorId: req.user.id, actorRole: req.user.role, action: 'job_settings_changed',
|
|
targetType: 'Job', targetId: req.params.name, metadata: { enabled: body.enabled, cron: body.cron }, ip: getClientIp(req),
|
|
});
|
|
res.json({ name: req.params.name, override: choice });
|
|
} catch (error) {
|
|
res.status(error.statusCode || 500).json({ message: safeErrorMessage(error) });
|
|
}
|
|
};
|
|
|
|
module.exports = { listJobs, runJobNow, updateJob };
|