Skip to content

a8n: Implement cancelCampaignPlan GraphQL mutation

Created by: mrnugget

This is a follow-up to RFC 42.

Currently the previewCampaignPlan mutation can run indefinitely (when wait = false in arguments, with wait = true the request timeout cancels the context.Contexts).

We need a cancelCampaignPlan mutation that

  • takes in a CampaignPlan.ID
  • cancels the CampaignPlan so that no new CampaignJobs are executed

We probably want to extend the BackgroundProcessState with a CANCELLED state so that clients know when a CampaignPlan has finished execution or when it's been cancelled.

https://github.com/sourcegraph/sourcegraph/blob/034cee47c83a7734cf04a4b5720717665b5a69db/cmd/frontend/graphqlbackend/schema.graphql#L484-L492


Thoughts on implementation

  • Add a CancelledAt field to CampaignPlan, null by default
  • In the cancelCampaignPlan mutation (see the stub here) we populate the field in a transaction
  • At the beginning of (&Runner).runJob we query the database to check whether the CampaignPlan has been cancelled. If so, we do an early return.
  • (Do we need to set an Error on the CampaignJob if the CampaignPlan has been cancelled? I don't think so)