feat: run jobs on instance creation when run_on_create is enabled
All checks were successful
CI / test (pull_request) Successful in 18s
CI / build-dev (pull_request) Has been skipped

Jobs with run_on_create=true in their config fire automatically
after a new instance is created. Runs fire-and-forget so they don't
delay the 201 response. Option exposed as a checkbox in each job's
detail panel.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-28 20:00:45 -04:00
parent c4ebb76deb
commit 817fdaef13
4 changed files with 41 additions and 5 deletions

View File

@@ -463,6 +463,13 @@ async function loadJobDetail(jobId) {
<label class="form-label" for="job-schedule">Poll interval (minutes)</label>
<input class="form-input" id="job-schedule" type="number" min="1" value="${job.schedule}" style="max-width:100px">
</div>
<div class="form-group">
<label class="form-label" style="display:flex;align-items:center;gap:8px;cursor:pointer">
<input type="checkbox" id="job-run-on-create" ${cfg.run_on_create ? 'checked' : ''}
style="accent-color:var(--accent);width:13px;height:13px">
Run on instance creation
</label>
</div>
${_renderJobConfigFields(job.key, cfg)}
<div class="job-actions">
<button class="btn btn-secondary" onclick="saveJobDetail(${job.id})">Save</button>
@@ -521,10 +528,12 @@ async function saveJobDetail(jobId) {
const apiKey = document.getElementById('job-cfg-api-key');
const apiUrl = document.getElementById('job-cfg-api-url');
const apiToken = document.getElementById('job-cfg-api-token');
if (tailnet) cfg.tailnet = tailnet.value.trim();
if (apiKey) cfg.api_key = apiKey.value;
if (apiUrl) cfg.api_url = apiUrl.value.trim();
if (apiToken) cfg.api_token = apiToken.value;
if (tailnet) cfg.tailnet = tailnet.value.trim();
if (apiKey) cfg.api_key = apiKey.value;
if (apiUrl) cfg.api_url = apiUrl.value.trim();
if (apiToken) cfg.api_token = apiToken.value;
const runOnCreate = document.getElementById('job-run-on-create');
if (runOnCreate) cfg.run_on_create = runOnCreate.checked;
const res = await fetch(`/api/jobs/${jobId}`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },