コンテンツにスキップ

タスク操作時のシーケンス

タスク操作時のシーケンスを以下に示します。 各シーケンスは、タスクの送信やキャンセルを行ってから操作が完了するまでの一連のステップを示しています。

[!NOTE] シーケンス図中に記載している /tasks, /tasks/{taskId}/cancel, /results エンドポイントは、実際には sampling タスク用と estimation タスク用の別々のエンドポイントに分かれています。 例えば、/tasks であれば、/tasks/sampling/tasks/estimation に分かれています。 sampling タスク用と estimation タスク用の両エンドポイントでのシーケンスは共通のため、シーケンス図上ではパス中の /sampling, /estimation の部分を省略して記載しています。

タスク実行のシーケンス (成功ケース)

タスクの実行が成功した場合のシーケンスを以下に示します。 User によるタスクの送信、Provider によるタスクの実行、User による結果の取得の一連の流れを示しています。

sequenceDiagram
    autonumber
    participant User as User (alice)
    participant Cloud as Cloud (Backend)
    participant Provider as Provider (Device ID is 'SC')

    User->>Cloud: POST /tasks { "code": "OPENQASM ...", ... }
    Note right of User: User submits a task
    Note over Cloud: A new task is created.
    Cloud-->>User: HTTP 200 OK { "taskId": <task ID-1> }

    User->>Cloud: GET /tasks/<task ID-1>/status
    Cloud-->>User: HTTP 200 OK { "taskId": <task ID-1>, "status": "submitted" }

    Note over Provider: Provider starts getting the tasks.
    Provider->>Cloud: GET /jobs
    Note over Cloud: The task status is updated to ready.
    Cloud-->>Provider: HTTP 200 OK

    Note over Provider: Provider starts execution of the tasks<br>and sends requests to update their statuses to running.
    Provider->>Cloud: PATCH /tasks/<task ID-1> { "status": "running" }
    Note over Cloud: The task status is updated to running.
    Cloud-->>Provider: HTTP 200 OK

    Provider->>Cloud: PATCH /tasks/<task ID-N> { "status": "running" }
    Note over Cloud: The task status is updated to running.
    Cloud-->>Provider: HTTP 200 OK

    User->>Cloud: GET /tasks/<task ID-1>/status
    Cloud-->>User: HTTP 200 OK { "taskId": <task ID-1>, "status": "running" }
    Note over Provider: The execution of the task <task ID-1> is successfully completed.
    Provider->>Cloud: POST /results { "taskId": <task ID-1>, "status": "succeeded", result: ... }

    Note over Cloud: The received result of the task is inserted to the DB,<br> then the task status is changed to succeeded (via a DB trigger).
    Cloud-->>Provider: HTTP 200 OK

    User->>Cloud: GET /tasks/<task ID-1>/status
    Cloud-->>User: HTTP 200 OK { "taskId": <task ID-1>, "status": "succeeded" }

    User->>Cloud: GET /results/<task ID-1>
    Cloud-->>User: HTTP 200 OK { "taskId": <task ID-1>, "status": "succeeded", "result": ... }

Provider は定期的に、タスクの実行・実行結果の送信、の流れを繰り返します。 上図では 1 回分の流れを記載しています。

各時点における DB 内のデータ

シーケンス図の各時点における、DB 内のデータのサンプルを以下に示します。
/tasks/sampling/tasks/estimation の 2 つのエンドポイントそれぞれに対して 1 回ずつタスクを送信した場合の例となっています。
以下の数字は、シーケンス図中の丸数字と対応しています。

タスク実行のシーケンス (失敗ケース)

タスクの実行に失敗した場合のシーケンスを以下に示します。 タスクの status が running に変化するまでは成功ケースと同様の流れです。図中の着色部分が、失敗した場合に特有の処理を示しています。

sequenceDiagram
    autonumber
    participant User as User (alice)
    participant Cloud as Cloud (Backend)
    participant Provider as Provider (Device ID is 'SVSim')

    User->>Cloud: POST /tasks { "code": "OPENQASM ...", ... }
    Note right of User: User submits a task
    Note over Cloud: A new task is created.
    Cloud-->>User: HTTP 200 OK { "taskId": <task ID-1> }

    User->>Cloud: GET /tasks/<task ID-1>/status
    Cloud-->>User: HTTP 200 OK { "taskId": <task ID-1>, "status": "submitted" }

    Note over Provider: Provider starts getting the tasks.
    Provider->>Cloud: GET /jobs
    Note over Cloud: The task status is updated to ready.
    Cloud-->>Provider: HTTP 200 OK

    Note over Provider: Provider starts execution of the tasks<br>and sends requests to update their statuses to running.
    Provider->>Cloud: PATCH /tasks/<task ID-1> { "status": "running" }
    Note over Cloud: The task status is updated to running.
    Cloud-->>Provider: HTTP 200 OK

    Provider->>Cloud: PATCH /tasks/<task ID-N> { "status": "running" }
    Note over Cloud: The task status is updated to running.
    Cloud-->>Provider: HTTP 200 OK

    User->>Cloud: GET /tasks/<task ID-1>/status
    Cloud-->>User: HTTP 200 OK { "taskId": <task ID-1>, "status": "running" }

    rect rgb(255, 240, 240)
        Note over Provider: The execution of the task <task ID-1> is failed.
        Provider->>Cloud: POST /results { "taskId": <task ID-1>, "status": "failed", "reason": ... }
        Note over Cloud: The received result of the task is inserted to the DB,<br> then the task status is changed to failed (via a DB trigger).
        Cloud-->>Provider: HTTP 200 OK

        User->>Cloud: GET /tasks/<task ID-1>/status
        Cloud-->>User: HTTP 200 OK { "taskId": <task ID-1>, "status": "failed" }

        User->>Cloud: GET /results/<task ID-1>
        Cloud-->>User: HTTP 200 OK { "taskId": <task ID-1>, "status": "failed", "reason": ...}
    end

各時点における DB 内のデータ

シーケンス図の各時点における、DB 内のデータのサンプルを以下に示します。
/tasks/estimation エンドポイントに対してタスクを送信した場合の例となっています。
以下の数字は、シーケンス図中の丸数字と対応しています。

タスクキャンセルのシーケンス

タスクをキャンセルした際のシーケンス図を以下に示します。 /tasks/{taskId}/cancel エンドポイントにリクエストを送った場合のシーケンスを示しています。

sequenceDiagram
    autonumber
    participant User as User (alice)
    participant Cloud as Cloud (Backend)
    participant Provider as Provider (Device ID is 'SVSim')

    User->>Cloud: POST /tasks/<task ID-1>/cancel
    Note right of User: User sends a cancel requests for the task <task ID-1>.
    Note over Cloud: The task status is updated to cancelled
    Cloud-->>User: HTTP 200 OK

    User->>Cloud: GET /tasks/<task ID-1>/status
    Cloud-->>User: HTTP 200 OK { "taskId": <task ID-1>, "status": "cancelled" }

    Note over Provider: Provider tries to cancel the executions of the tasks.
    Note over Provider: The execution of the task <task ID-1> is successfully cancelled.
    Provider->>Cloud: POST /results { "taskId": <task ID-1>, "status": "cancelled", "reason": ... }

    Note over Cloud: The received result of the task is inserted to the DB.
    Cloud-->>Provider: HTTP 200 OK

    User->>Cloud: GET /tasks/<task ID-1>/status
    Cloud-->>User: HTTP 200 OK { "taskId": <task ID-1>, "status": "cancelled" }

    User->>Cloud: GET /results/<task ID-1>
    Cloud-->>User: HTTP 200 OK { "taskId": <task ID-1>, "status": "cancelled", "reason": ... }

Provider は定期的に、タスク実行のキャンセル・キャンセル結果の送信、の流れを繰り返します。 上図では 1 回分の流れを記載しています。

各時点における DB 内のデータ

シーケンス図の各時点における、DB 内のデータのサンプルを以下に示します。
/tasks/sampling/{taskId}/cancel エンドポイントに対してリクエストした場合の例となっています。
以下の数字は、シーケンス図中の丸数字と対応しています。