Skip to content

a8n: Implement `cancelCampaignPlan` mutation

Administrator requested to merge a8n/cancel-campaign-plan into master

Created by: mrnugget

This implements the cancelCampaignPlan mutation that marks a CampaignPlan as cancelled in its BackgroundProcessStatus and stops all enqueued CampaignJobs from running.

It does this by

  • adding a canceled_at field on campaign_plans and setting that in cancelCampaignPlan in case it hasn't been set.
  • checking whether the the CampaignPlan has been canceled before executing a single CampaignJob. If it has, it marks the CampaignJob as errored.
  • extending the BackgroundProcessStatus (in the GraphQL API and in the backend) with a new CANCELED state that's returned when a CampaignPlan has been executed.

Note: this is not the most performant solution since we still do a SELECT and UPDATE for every CampaignJob if the CampaignPlan has been cancelled. But it's by far the most straightforward and easiest to debug solution.

Alternatives:

  1. stop the workers in Runner once the plan has been executed. But in that case we'd need to do some concurrency foo to mark the WaitGroup as done.
  2. add a canceled_at on campaign_jobs, set it along with campaign_plan.canceled_at and then do a SELECT (no UPDATE) to check whether it's been set before executing a job.

I think it's fine as it is and the SELECT/UPDATEs won't be a problem for a long time, but happy about suggestions :)

Merge request reports

Loading