# NOTE: Do not upgrade past Swagger 2. zclient does not support OpenAPI 3 unless
# https://github.com/Yelp/bravado/issues/306 is resolved.
swagger: "2.0"
info:
  description: "PipeDream Requeue Service"
  version: "1.0.0"
  title: "PipeDream Requeue Service"
  contact:
    name: "Infra"
    email: "infrateam@zoox.com"
    url: "https://git.zooxlabs.com/zooxco/driving"
# Your API spec goes here.  https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md
basePath: /v1
paths:
  /pipeline/{pipeId}:
    post:
      summary: "Initialize requeues for a pipeline by uploading the pipedef."
      operationId: "initialize"
      produces:
        - application/json
      parameters:
        - name: "pipeId"
          in: "path"
          type: "string"
          description: "PipeID of pipeline."
          required: True
        - name: "pipedef"
          in: "body"
          description: "PipeDef of pipeline."
          required: True
          schema:
            $ref: "#/definitions/PipeDef"
      responses:
        "200":
          description: "successful request"
          schema:
            $ref: "#/definitions/InitializeResponse"
  /pipeline/{pipeId}/requeueinfo:
    post:
      summary: "Get information on retries for a pipedef"
      operationId: "requeue_info"
      produces:
        - application/json
      parameters:
        - name: "pipeId"
          in: "path"
          type: "string"
          description: "PipeID of pipeline."
          required: True
      responses:
        "200":
          description: "successful request"
          schema:
            $ref: "#/definitions/RequeueInfoResponse"
  /requeue:
    post:
      summary: "Request a requeue for the PipeDream task."
      operationId: "requeue"
      produces:
        - application/json
      parameters:
        - name: "requeueTask"
          in: "body"
          description: "PipeDream task to requeue."
          required: True
          schema:
            $ref: "#/definitions/RequeueTask"
      responses:
        "200":
          description: "successful request"
          schema:
            $ref: "#/definitions/RequeueResponse"

  /metrics:
    get:
      tags:
        - "metrics"
      summary: "pipedream queue metrics api"
      description: "Return prometheus flatten metrics."
      operationId: "getMetrics"
      produces:
      - "text/plain; charset=utf-8"
      responses:
        "200":
          description: OK
          schema:
            type: string

definitions:
  PipeDef:
    type: object
    properties:
      job:
        type: "array"
        items:
          type: "object"
          description: "Stage definition."
          properties:
            name:
              type: "string"
              description: "Stage name."
  InitializeResponse:
    type: object
    properties:
      autoRetryBudget:
        type: "integer"
        description: "The autoRetryBudget initialize for the pipeline."
  RequeueTask:
    type: object
    properties:
      pipeId:
        type: "string"
        description: "PipeID of pipeline."
      stageName:
        type: "string"
        description: "Name of stage."
      taskIndex:
        type: "integer"
        description: "Task index."
      slurmId:
        type: "string"
        description: "Slurm job ID."
    required:
      - "pipeId"
      - "stageName"
      - "taskIndex"
      - "slurmId"
  RequeueResponse:
    type: object
    properties:
      requeued:
        type: "boolean"
        description: "Whether the requeue was performed."
      delay:
        type: "integer"
        description: "How long in seconds the job will wait before being eligible for scheduling."
  RequeueInfoResponse:
    type: "object"
    properties:
      requeue_count:
        type: "integer"
        description: "Sum of requeues calculated as per the requeue algorithm"
      tasks:
        type: "array"
        items:
          type: "object"
          properties:
            pipe_id:
              type: string
            stage_name:
              type: string
            task_index:
              type: "integer"
            requeue_count:
              type: "integer"
