Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 22, 2025

On application restart, all tasks were unconditionally reset to idle status, causing running tasks to display incorrectly in the UI.

Changes

Added PID validation utility (back/config/util.ts)

  • isPidRunning(): Uses process.kill(pid, 0) to check process existence without termination
  • Validates edge cases: null, undefined, zero, negative, float values

Modified initialization logic (back/loaders/initData.ts)

  • Check each task's PID before resetting status
  • Preserve status for tasks with running processes
  • Bulk update only tasks requiring reset (N→1 database operations)
  • Fetch only id and pid fields to reduce memory overhead
// Before: unconditional reset
await CrontabModel.update({ status: CrontabStatus.idle }, { where: {} });

// After: selective reset with PID validation
const allCrons = await CrontabModel.findAll({ attributes: ['id', 'pid'], raw: true });
const idsToReset = allCrons
  .filter(cron => !(cron.pid != null && isPidRunning(cron.pid)))
  .map(cron => cron.id)
  .filter(id => id != null);

if (idsToReset.length > 0) {
  await CrontabModel.update(
    { status: CrontabStatus.idle, pid: undefined },
    { where: { id: { [Op.in]: idsToReset } } }
  );
}
Original prompt

This section details on the original issue you should resolve

<issue_title>运行状态异常</issue_title>
<issue_description>### Qinglong version

v2.20.0

Steps to reproduce

任务还在运行中,但是重新打开面板就会变成空闲中

What is expected?

Image

What is actually happening?

Image

System Info

Any additional comments?

No response</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI self-assigned this Dec 22, 2025
@vercel
Copy link

vercel bot commented Dec 22, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
qinglong Ready Ready Preview, Comment Dec 22, 2025 3:04pm
qinglong-back Ready Ready Preview, Comment Dec 22, 2025 3:04pm

Copilot AI changed the title [WIP] Fix abnormal runtime status display on panel Preserve running task status on application restart Dec 22, 2025
Copilot AI requested a review from whyour December 22, 2025 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

运行状态异常

2 participants