> ## Documentation Index
> Fetch the complete documentation index at: https://docs.eorion.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 锁定

> Lock an external task by a given id for a specified worker and amount of time.



## OpenAPI

````yaml POST /external-task/{id}/lock
openapi: 3.0.2
info:
  title: ORION Platform REST API
  description: OpenApi Spec for ORION Camunda Platform REST API.
  version: 7.22.6-ee
  license:
    name: Apache License 2.0
    url: http://www.apache.org/licenses/LICENSE-2.0.html
servers:
  - url: http://{host}:{port}/{contextPath}
    description: The API server for the default process engine
    variables:
      host:
        default: localhost
      port:
        default: '8080'
      contextPath:
        default: engine-rest
  - url: http://{host}:{port}/{contextPath}/engine/{engineName}
    description: The API server for a named process engine
    variables:
      host:
        default: localhost
      port:
        default: '8080'
      contextPath:
        default: engine-rest
      engineName:
        default: default
  - url: '{url}'
    description: The API server with a custom url
    variables:
      url:
        default: ''
security:
  - basicAuth: []
tags:
  - name: Authorization
  - name: Batch
  - name: Condition
  - name: Decision Definition
  - name: Decision Requirements Definition
  - name: Deployment
  - name: Engine
  - name: Event Subscription
  - name: Execution
  - name: External Task
  - name: Filter
  - name: Group
  - name: Historic Activity Instance
  - name: Historic Batch
  - name: Historic Decision Definition
  - name: Historic Decision Instance
  - name: Historic Decision Requirements Definition
  - name: Historic Detail
  - name: Historic External Task Log
  - name: Historic Identity Link Log
  - name: Historic Incident
  - name: Historic Job Log
  - name: Historic Process Definition
  - name: Historic Process Instance
  - name: Historic Task Instance
  - name: Historic User Operation Log
  - name: Historic Variable Instance
  - name: History Cleanup
  - name: Identity
  - name: Incident
  - name: Job
  - name: Job Definition
  - name: Message
  - name: Metrics
  - name: Migration
  - name: Modification
  - name: Process Definition
  - name: Process Instance
  - name: Signal
  - name: Schema Log
  - name: Task
  - name: Task Attachment
  - name: Task Comment
  - name: Task Identity Link
  - name: Task Local Variable
  - name: Task Variable
  - name: Telemetry
  - name: Tenant
  - name: User
  - name: Variable Instance
  - name: Version
externalDocs:
  description: Find out more about ORION Rest API
  url: https://docs.eorion.com
paths:
  /external-task/{id}/lock:
    post:
      tags:
        - External Task
      description: >-
        Lock an external task by a given id for a specified worker and amount of
        time.
      operationId: lock
      parameters:
        - name: id
          in: path
          schema:
            type: string
          required: true
          description: The id of the external task.
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/LockExternalTaskDto'
            examples:
              example-1:
                summary: POST /external-task/anId/lock
                value:
                  workerId: anId
                  lockDuration: 100000
      responses:
        '204':
          description: Request successful.
        '400':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ExceptionDto'
          description: >-
            In case the lock duration is negative or the external task is
            already locked by

            a different worker, an exception of type `InvalidRequestException`
            is returned. See the

            [Introduction](https://docs.camunda.org/manual/7.22/reference/rest/overview/#error-handling)

            for the error response format.
        '404':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ExceptionDto'
          description: >-
            Returned if the task does not exist. This could indicate a wrong
            task id as well as a cancelled task,

            e.g., due to a caught BPMN boundary event. See the

            [Introduction](https://docs.camunda.org/manual/7.22/reference/rest/overview/#error-handling)

            for the error response format.
components:
  schemas:
    LockExternalTaskDto:
      allOf:
        - type: object
          properties:
            lockDuration:
              type: integer
              format: int64
              description: >-
                The duration to lock the external task for in milliseconds.

                **Note:** Attempting to lock an already locked external task
                with the same `workerId`

                will succeed and a new lock duration will be set, starting from
                the current moment.
        - $ref: '#/components/schemas/HandleExternalTaskDto'
    ExceptionDto:
      title: ExceptionDto
      type: object
      properties:
        type:
          type: string
          nullable: true
          description: An exception class indicating the occurred error.
        message:
          type: string
          nullable: true
          description: A detailed message of the error.
        code:
          type: number
          description: >-
            The code allows your client application to identify the error in an
            automated fashion.

            You can look up the meaning of all built-in codes and learn how to
            add custom codes

            in the [User
            Guide](https://docs.camunda.org/manual/7.22/user-guide/process-engine/error-handling/#exception-codes).
    HandleExternalTaskDto:
      type: object
      properties:
        workerId:
          type: string
          description: >-
            **Mandatory.** The ID of the worker who is performing the operation
            on the external task.

            If the task is already locked, must match the id of the worker who
            has most recently

            locked the task.
  securitySchemes:
    basicAuth:
      type: http
      scheme: basic

````