a8n: Implement `cancelCampaignPlan` mutation
Created by: mrnugget
This implements the cancelCampaignPlan
mutation that marks a CampaignPlan
as cancelled in its BackgroundProcessStatus
and stops all enqueued CampaignJob
s from running.
It does this by
- adding a
canceled_at
field oncampaign_plans
and setting that incancelCampaignPlan
in case it hasn't been set. - checking whether the the
CampaignPlan
has been canceled before executing a singleCampaignJob
. If it has, it marks theCampaignJob
as errored. - extending the
BackgroundProcessStatus
(in the GraphQL API and in the backend) with a newCANCELED
state that's returned when aCampaignPlan
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:
- 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 theWaitGroup
as done. - add a
canceled_at
oncampaign_jobs
, set it along withcampaign_plan.canceled_at
and then do aSELECT
(noUPDATE
) 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 :)