dgx-spark-playbooks/nvidia/txt2kg/assets/frontend/app/api/stop-processing/route.ts

66 lines
2.0 KiB
TypeScript
Raw Normal View History

2025-12-02 19:43:52 +00:00
//
// SPDX-FileCopyrightText: Copyright (c) 1993-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
2025-10-06 17:05:41 +00:00
import { NextRequest, NextResponse } from 'next/server'
// Global flag to track if processing should be stopped
let shouldStopProcessing = false
// Function to check if processing should stop
export function getShouldStopProcessing(): boolean {
return shouldStopProcessing
}
// Function to reset the stop flag
export function resetStopProcessing(): void {
shouldStopProcessing = false
}
// Function to set the stop flag
export function setStopProcessing(): void {
shouldStopProcessing = true
}
export async function POST(request: NextRequest) {
try {
console.log('Stop processing request received')
// Set the global flag to stop processing
shouldStopProcessing = true
// You could also implement more sophisticated cancellation here
// such as canceling ongoing HTTP requests, clearing queues, etc.
return NextResponse.json({
success: true,
message: 'Processing stop signal sent'
})
} catch (error) {
console.error('Error stopping processing:', error)
return NextResponse.json(
{ error: 'Failed to stop processing' },
{ status: 500 }
)
}
}
export async function GET(request: NextRequest) {
// Allow checking the current stop status
return NextResponse.json({
shouldStop: shouldStopProcessing
})
}