cancelScheduledAction

The cancelScheduledAction method cancels a previously-scheduled event in the content source.

Return Value
Promise<{ cancelledScheduledActionId: string }>

This method should use the output ID from createScheduledAction to cancel a previously-scheduled publish event.

See getScheduledActions for more information on the feature.

Parameters

scheduledActionId

string

ID value that was returned from createScheduledAction.

userContext

User<UserContext>

See UserContext for details.

Example

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
import type {
  ContentSourceInterface,
  ScheduledAction,
  ScheduledActionActionType,
} from '@stackbit/types'

interface UserContext {
  accessToken: string
}

export class MyContentSource implements ContentSourceInterface<UserContext> {
  async cancelScheduledAction({
    scheduledActionId,
    userContext,
  }: {
    scheduledActionId: string
    userContext?: UserContext
  }): Promise<{ cancelledScheduledActionId: string }> {
    // optionally use userContext.accessToken to cancel the schedule on the user's behalf
    await this.apiClient.cancelScheduledAction(scheduledActionId)
    return { cancelledScheduledActionId: scheduledActionId }
  }

  // other methods ...
}

Managing State

When possible, we recommend changing the state of a previously-scheduled action (to the equivalent of "canceled"), rather than deleting it. Some content sources may not support this behavior.

Logging

When this method fails, the error is rendered in the UI so that editors receive feedback on the failure.

This method should be implemented alongside the other scheduled action methods: