From 2c57ada73907182c6703b49a2efcfbc9cff6b71b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 20 Nov 2025 16:11:56 +0000 Subject: [PATCH] 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> --- back/services/subscription.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/back/services/subscription.ts b/back/services/subscription.ts index 7ae3b789..2a06b101 100644 --- a/back/services/subscription.ts +++ b/back/services/subscription.ts @@ -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) {