Fix: Disable/enable associated cron tasks when subscription is disabled/enabled

When a subscription is disabled, the associated cron tasks (created by the subscription) were still running and updating scripts. This fix ensures that:
- When disabling a subscription, all cron tasks with matching sub_id are also disabled
- When enabling a subscription, all cron tasks with matching sub_id are also enabled

This addresses the actual root cause: subscription tasks don't run when disabled (as the owner correctly pointed out), but the cron tasks created by those subscriptions were still active.

Co-authored-by: whyour <22700758+whyour@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2025-11-20 16:11:56 +00:00
parent 87a1a3d2eb
commit 2c57ada739

View File

@ -112,9 +112,7 @@ export default class SubscriptionService {
}
public async setSshConfig() {
const docs = await SubscriptionModel.findAll({
where: { is_disabled: 0 },
});
const docs = await SubscriptionModel.findAll();
await this.sshKeyService.setSshConfig(docs);
}
@ -348,18 +346,15 @@ export default class SubscriptionService {
public async disabled(ids: number[]) {
await SubscriptionModel.update({ is_disabled: 1 }, { where: { id: ids } });
const docs = await SubscriptionModel.findAll({ where: { id: ids } });
// Remove SSH keys for disabled subscriptions
for (const doc of docs) {
if (doc.type === 'private-repo' && doc.pull_type === 'ssh-key') {
const { alias } = doc;
const { host } = formatUrl(doc);
await this.sshKeyService.removeSSHKey(alias, host, doc.proxy);
}
}
await this.setSshConfig();
for (const doc of docs) {
await this.handleTask(doc.get({ plain: true }), false);
}
// Disable associated cron tasks
const crons = await CrontabModel.findAll({ where: { sub_id: ids } });
if (crons?.length) {
await this.crontabService.disabled(crons.map((x) => x.id!));
}
}
public async enabled(ids: number[]) {
@ -369,6 +364,11 @@ export default class SubscriptionService {
for (const doc of docs) {
await this.handleTask(doc.get({ plain: true }));
}
// Enable associated cron tasks
const crons = await CrontabModel.findAll({ where: { sub_id: ids } });
if (crons?.length) {
await this.crontabService.enabled(crons.map((x) => x.id!));
}
}
public async log(id: number) {