Skip to content

Adds workflow events subscription api

What does this MR do and why?

The MR introduce a new subscription type called workflow_events_updated to the GraphQL API. This subscription allows authorized users to receive real-time updates whenever the checkpoints or events of a workflow are modified.

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

GraphQL subscription
Screenshot 2024-07-16 at 5.34.13 PM.png

How to set up and validate locally

  1. Create a duo workflow for a project

    POST /api/v4/ai/duo_workflows/workflows?private_token=<YOUR_TOKEN>&project_id=[PROJECT_ID]
  2. Subscribe to the GraphQL subscription workflowEventsUpdated using a GraphQL subscription client. Note that GraphiQL that we use for production does not have support subscriptions. I used https://gitlab.com/DylanGriffith/graphql-susbcription-client. Follow steps in README.md for the setup. After running node subscribe.js in your console, you should see something like

    Using query:
    subscription getWorkflowEventSubscription($workflowId: AiDuoWorkflowsWorkflowID!) {
      workflowEventsUpdated(workflowId: $workflowId) {
        checkpoint
        metadata
        errors
      }
    }
    
    Using variables:
    {
      "workflowId": "gid://gitlab/Ai::DuoWorkflows::Workflow/6"
    }
    
    Subscribing...
    Received message:
    {"result":{"data":{"workflowEventsUpdated":null}},"more":true}
  3. Create checkpoint for the above workflow. This should trigger the subscription workflowEventsUpdated

    POST /api/v4/ai/duo_workflows/workflows/[WORKFLOW_ID_FROM_STEP_ABOVE]/checkpoints?private_token=[YOUR_TOKEN]
    Content-Type: application/json
    
    {
      "thread_ts": "2024-07-16 11:00:10 UTC",
      "checkpoint" : {
        "key": "value"
      },
      "metadata": {
        "key": "value"
      }
    }
    
  4. Check the subscription console, you should see something like

    
    Using query:
    subscription getWorkflowEventSubscription($workflowId: AiDuoWorkflowsWorkflowID!) {
      workflowEventsUpdated(workflowId: $workflowId) {
        checkpoint
        metadata
        errors
      }
    }
    
    Using variables:
    {
      "workflowId": "gid://gitlab/Ai::DuoWorkflows::Workflow/6"
    }
    
    Subscribing...
    Received message:
    {"result":{"data":{"workflowEventsUpdated":null}},"more":true}
    Received message:
    {"result":{"data":{"workflowEventsUpdated":{"checkpoint":"{\"key\":\"value\"}","metadata":"{\"key\":\"value\"}","errors":[]}}},"more":true}

Related to #469680

Edited by Surabhi Suman

Merge request reports