Opérations Asynchrones
Opérations de longue durée
Gérez les opérations asynchrones avec des callbacks, des webhooks et des mises à jour de statut en temps réel.
Démarrer une Opération Asynchrone
POST /api/{tenantId}/{projectId}/async/operation
Initie une opération asynchrone de longue durée et renvoie un ID d'opération pour le suivi. Prend en charge les URL de rappel et les notifications webhook.
Paramètres
| Paramètre | Type | Emplacement | Description |
|---|---|---|---|
tenantId |
GUID | Chemin | L'identifiant du locataire |
projectId |
GUID | Chemin | L'identifiant du projet |
Corps de la requête
{
"operationType": "ProcessMiningAnalysis",
"operationName": "Comprehensive Customer Journey Analysis",
"operationDescription": "Deep analysis of customer interaction patterns with advanced ML algorithms",
"priority": "High",
"parameters": {
"datasetId": "880e8400-e29b-41d4-a716-446655440000",
"analysisType": "comprehensive",
"timeWindow": {
"startDate": "2024-01-01",
"endDate": "2024-01-31"
},
"algorithmSettings": {
"useAdvancedML": true,
"enableAnomalyDetection": true,
"performanceOptimization": "high_accuracy"
},
"outputOptions": {
"generateReports": true,
"createVisualizations": true,
"exportFormats": ["PDF", "CSV", "JSON"]
}
},
"callbacks": {
"onProgress": "https://your-app.com/webhooks/progress",
"onCompletion": "https://your-app.com/webhooks/completion",
"onError": "https://your-app.com/webhooks/error"
},
"notifications": {
"email": ["analyst@company.com", "manager@company.com"],
"slack": {
"channel": "#process-mining",
"mentionUsers": ["@analyst", "@data-team"]
}
},
"timeout": 7200,
"retryPolicy": {
"maxRetries": 3,
"retryDelay": 300,
"backoffMultiplier": 2.0
}
}
Réponse
{
"operationId": "op-ff0e8400-e29b-41d4-a716-446655440000",
"operationType": "ProcessMiningAnalysis",
"operationName": "Comprehensive Customer Journey Analysis",
"status": "Initiated",
"estimatedDuration": "45-60 minutes",
"estimatedCompletion": "2024-01-20T12:15:00Z",
"trackingUrl": "/api/{tenantId}/{projectId}/async/operation/op-ff0e8400-e29b-41d4-a716-446655440000",
"webhooksRegistered": 3,
"priority": "High",
"dateCreated": "2024-01-20T11:15:00Z",
"timeoutAt": "2024-01-20T13:15:00Z",
"resourcesAllocated": {
"cpuUnits": 4,
"memoryGB": 8,
"estimatedCost": "$2.45"
}
}
Obtenir le Statut de l'Opération
GET /api/{tenantId}/{projectId}/async/operation/{operationId}
Récupère le statut actuel et la progression d'une opération asynchrone, y compris des informations détaillées sur l'exécution et les temps de complétion estimés.
Paramètres
| Paramètre | Type | Emplacement | Description |
|---|---|---|---|
operationId |
string | Chemin | L'identifiant de l'opération |
Réponse
{
"operationId": "op-ff0e8400-e29b-41d4-a716-446655440000",
"operationType": "ProcessMiningAnalysis",
"operationName": "Comprehensive Customer Journey Analysis",
"status": "Running",
"progress": {
"percentage": 67,
"currentPhase": "Machine Learning Analysis",
"phasesCompleted": 2,
"totalPhases": 3,
"startTime": "2024-01-20T11:18:00Z",
"elapsedTime": "23 minutes 15 seconds",
"estimatedRemaining": "15-20 minutes",
"estimatedCompletion": "2024-01-20T12:05:00Z"
},
"execution": {
"executionId": "exec-aa1e8400-e29b-41d4-a716-446655440000",
"workerNode": "async-worker-03",
"resourceUsage": {
"cpuUsage": 78,
"memoryUsage": "6.2 GB",
"diskUsage": "1.3 GB",
"networkIO": "45 MB"
},
"processedRecords": 125430,
"totalRecords": 187250,
"processingRate": "1890 records/minute"
},
"phases": [
{
"phaseName": "Data Loading & Validation",
"status": "Completed",
"startTime": "2024-01-20T11:18:00Z",
"endTime": "2024-01-20T11:25:00Z",
"duration": "7 minutes",
"recordsProcessed": 187250,
"validationResults": {
"validRecords": 187248,
"errorRecords": 2,
"dataQualityScore": 99.9
}
},
{
"phaseName": "Process Discovery",
"status": "Completed",
"startTime": "2024-01-20T11:25:00Z",
"endTime": "2024-01-20T11:38:00Z",
"duration": "13 minutes",
"results": {
"activitiesDiscovered": 52,
"processVariants": 347,
"uniquePaths": 289
}
},
{
"phaseName": "Machine Learning Analysis",
"status": "Running",
"startTime": "2024-01-20T11:38:00Z",
"progress": 72,
"currentActivity": "Training anomaly detection models",
"modelsTraining": 3,
"modelsCompleted": 2
},
{
"phaseName": "Report Generation",
"status": "Pending",
"estimatedStartTime": "2024-01-20T11:55:00Z",
"estimatedDuration": "8-10 minutes"
}
],
"callbacks": {
"progressCallbacksSent": 15,
"lastProgressCallback": "2024-01-20T11:40:00Z",
"callbacksSuccessful": 15,
"callbacksFailed": 0
},
"dateCreated": "2024-01-20T11:15:00Z",
"timeoutAt": "2024-01-20T13:15:00Z",
"priority": "High"
}
Lister les Opérations Asynchrones
GET /api/{tenantId}/{projectId}/async/operations
Récupère une liste d'opérations asynchrones avec des options de filtrage et de pagination. Utile pour surveiller plusieurs opérations de longue durée.
Paramètres de requête
| Paramètre | Type | Description |
|---|---|---|
status |
string | Filtrer par statut : Initiated, Running, Completed, Failed, Cancelled, Timeout |
operationType |
string | Filtrer par type d'opération : ProcessMiningAnalysis, DataEnrichment, ReportGeneration |
priority |
string | Filtrer par priorité : Low, Normal, High, Critical |
dateFrom |
datetime | Filtrer les opérations à partir de cette date |
dateTo |
datetime | Filtrer les opérations jusqu'à cette date |
includeDetails |
boolean | Inclure des informations d'exécution détaillées (par défaut : false) |
page |
integer | Numéro de page pour la pagination (par défaut : 1) |
pageSize |
integer | Nombre d'éléments par page (par défaut : 20, max : 100) |
Réponse
{
"operations": [
{
"operationId": "op-ff0e8400-e29b-41d4-a716-446655440000",
"operationType": "ProcessMiningAnalysis",
"operationName": "Comprehensive Customer Journey Analysis",
"status": "Running",
"progress": 67,
"priority": "High",
"startTime": "2024-01-20T11:18:00Z",
"estimatedCompletion": "2024-01-20T12:05:00Z",
"currentPhase": "Machine Learning Analysis",
"resourceUsage": {
"cpuUsage": 78,
"memoryUsage": "6.2 GB"
}
},
{
"operationId": "op-gg1e8400-e29b-41d4-a716-446655440000",
"operationType": "DataEnrichment",
"operationName": "Sales Data Processing",
"status": "Completed",
"progress": 100,
"priority": "Normal",
"startTime": "2024-01-20T10:45:00Z",
"endTime": "2024-01-20T11:10:00Z",
"duration": "25 minutes",
"recordsProcessed": 89420
}
],
"summary": {
"totalOperations": 47,
"running": 3,
"completed": 41,
"failed": 2,
"cancelled": 1
},
"page": 1,
"pageSize": 20,
"hasNextPage": true
}
Annuler une Opération Asynchrone
DELETE /api/{tenantId}/{projectId}/async/operation/{operationId}
Annule une opération asynchrone en cours ou en attente. L'opération sera arrêtée proprement, en conservant tout travail déjà effectué.
Corps de la requête (optionnel)
{
"reason": "User requested cancellation due to changed requirements",
"preservePartialResults": true,
"forceTermination": false,
"notifyCallbacks": true
}
Réponse
{
"operationId": "op-ff0e8400-e29b-41d4-a716-446655440000",
"status": "Cancelled",
"cancellationTime": "2024-01-20T11:42:00Z",
"reason": "User requested cancellation due to changed requirements",
"progressAtCancellation": 67,
"phaseAtCancellation": "Machine Learning Analysis",
"partialResults": {
"available": true,
"completedPhases": 2,
"downloadUrls": [
"https://api.mindzie.com/downloads/partial-results-ff0e8400.zip"
]
},
"resourcesReleased": {
"cpuUnits": 4,
"memoryGB": 8,
"costSaved": "$1.20"
},
"cancelledBy": "user123"
}
Obtenir les Résultats de l'Opération
GET /api/{tenantId}/{projectId}/async/operation/{operationId}/results
Récupère les résultats complets d'une opération asynchrone terminée, y compris toutes les sorties générées, rapports et artefacts téléchargeables.
Paramètres de requête
| Paramètre | Type | Description |
|---|---|---|
format |
string | Format de la réponse : summary, detailed, download (par défaut : summary) |
includeArtifacts |
boolean | Inclure les artefacts téléchargeables dans la réponse (par défaut : true) |
phase |
string | Obtenir les résultats d'une phase spécifique uniquement |
Réponse
{
"operationId": "op-ff0e8400-e29b-41d4-a716-446655440000",
"operationType": "ProcessMiningAnalysis",
"operationName": "Comprehensive Customer Journey Analysis",
"status": "Completed",
"completionTime": "2024-01-20T12:03:00Z",
"totalDuration": "45 minutes",
"success": true,
"summary": {
"recordsAnalyzed": 187248,
"processVariants": 347,
"anomaliesDetected": 23,
"modelsGenerated": 3,
"reportsCreated": 5,
"dataQualityScore": 94.7,
"overallConfidenceScore": 91.2
},
"phaseResults": [
{
"phaseName": "Data Loading & Validation",
"status": "Completed",
"results": {
"recordsLoaded": 187250,
"validRecords": 187248,
"dataQualityScore": 99.9,
"validationErrors": [
{
"type": "Missing Timestamp",
"count": 2,
"resolved": true
}
]
}
},
{
"phaseName": "Process Discovery",
"status": "Completed",
"results": {
"processModel": {
"activities": 52,
"transitions": 178,
"variants": 347,
"complexity": "Medium-High"
},
"performanceMetrics": {
"averageCycleTime": "4.2 hours",
"medianCycleTime": "3.1 hours",
"bottleneckActivities": ["Review Application", "Manager Approval"],
"efficiency": 78.3
}
}
},
{
"phaseName": "Machine Learning Analysis",
"status": "Completed",
"results": {
"anomalies": {
"detected": 23,
"highSeverity": 5,
"mediumSeverity": 12,
"lowSeverity": 6,
"falsePositiveRate": 0.03
},
"predictions": {
"cycleTimePrediction": {
"accuracy": 0.89,
"meanAbsoluteError": "0.3 hours"
},
"pathPrediction": {
"accuracy": 0.92,
"confidence": 0.87
}
},
"patterns": {
"frequentPatterns": 15,
"rarePatterns": 8,
"criticalPaths": 3
}
}
}
],
"artifacts": [
{
"name": "Process Mining Analysis Report",
"type": "Report",
"format": "PDF",
"size": "3.2 MB",
"downloadUrl": "https://api.mindzie.com/downloads/report-ff0e8400.pdf",
"description": "Comprehensive analysis report with insights and recommendations"
},
{
"name": "Process Model Visualization",
"type": "Visualization",
"format": "SVG",
"size": "890 KB",
"downloadUrl": "https://api.mindzie.com/downloads/process-map-ff0e8400.svg",
"description": "Interactive process flow diagram"
},
{
"name": "Anomaly Detection Results",
"type": "Dataset",
"format": "CSV",
"size": "1.8 MB",
"downloadUrl": "https://api.mindzie.com/downloads/anomalies-ff0e8400.csv",
"description": "Detailed anomaly analysis with severity scores"
},
{
"name": "Predictive Models",
"type": "Model",
"format": "PKL",
"size": "45.7 MB",
"downloadUrl": "https://api.mindzie.com/downloads/models-ff0e8400.zip",
"description": "Trained ML models for cycle time and path prediction"
}
],
"performance": {
"totalExecutionTime": "45 minutes",
"resourceUtilization": {
"averageCpuUsage": 72,
"peakMemoryUsage": "7.8 GB",
"totalCpuHours": 3.0,
"totalCost": "$2.31"
},
"throughput": "4161 records/minute",
"efficiency": 87.2
},
"recommendations": [
{
"category": "Process Optimization",
"priority": "High",
"recommendation": "Focus on reducing wait times in 'Manager Approval' activity",
"expectedImprovement": "25% reduction in overall cycle time"
},
{
"category": "Data Quality",
"priority": "Medium",
"recommendation": "Implement automated timestamp validation",
"expectedImprovement": "Improved data quality score to 99.5%"
}
]
}
Enregistrer un Webhook
POST /api/{tenantId}/{projectId}/async/webhooks
Enregistre un point de terminaison webhook pour recevoir des notifications en temps réel sur les opérations asynchrones. Prend en charge plusieurs types d'événements et un filtrage personnalisé.
Corps de la requête
{
"webhookUrl": "https://your-app.com/webhooks/async-operations",
"webhookName": "Main Operations Webhook",
"events": [
"operation.started",
"operation.progress",
"operation.phase.completed",
"operation.completed",
"operation.failed",
"operation.cancelled"
],
"filters": {
"operationTypes": ["ProcessMiningAnalysis", "DataEnrichment"],
"priorities": ["High", "Critical"],
"minProgressIncrement": 10
},
"authentication": {
"type": "hmac-sha256",
"secret": "your-webhook-secret-key"
},
"retryPolicy": {
"maxRetries": 5,
"retryDelay": 60,
"backoffMultiplier": 2.0,
"maxDelay": 3600
},
"headers": {
"X-Source": "mindzie-api",
"X-Environment": "production"
}
}
Réponse
{
"webhookId": "wh-123e8400-e29b-41d4-a716-446655440000",
"webhookUrl": "https://your-app.com/webhooks/async-operations",
"webhookName": "Main Operations Webhook",
"status": "Active",
"eventsSubscribed": [
"operation.started",
"operation.progress",
"operation.phase.completed",
"operation.completed",
"operation.failed",
"operation.cancelled"
],
"filters": {
"operationTypes": ["ProcessMiningAnalysis", "DataEnrichment"],
"priorities": ["High", "Critical"],
"minProgressIncrement": 10
},
"createdAt": "2024-01-20T11:45:00Z",
"lastDelivery": null,
"deliveryStats": {
"totalDeliveries": 0,
"successfulDeliveries": 0,
"failedDeliveries": 0,
"averageResponseTime": null
}
}
Relancer une Opération Échouée
POST /api/{tenantId}/{projectId}/async/operation/{operationId}/retry
Relance une opération asynchrone échouée avec des modifications optionnelles des paramètres. Peut reprendre depuis le point d'échec ou redémarrer complètement.
Corps de la requête
{
"retryMode": "resume",
"retryReason": "Infrastructure issue resolved, retrying with increased resources",
"modifyParameters": true,
"updatedParameters": {
"algorithmSettings": {
"useAdvancedML": true,
"enableAnomalyDetection": true,
"performanceOptimization": "high_throughput"
},
"resourceAllocation": {
"cpuUnits": 6,
"memoryGB": 12,
"priority": "Critical"
}
},
"retryPolicy": {
"maxRetries": 2,
"retryDelay": 180,
"backoffMultiplier": 1.5
},
"newTimeout": 10800,
"preserveOriginalResults": true
}
Réponse
{
"originalOperationId": "op-ff0e8400-e29b-41d4-a716-446655440000",
"newOperationId": "op-retry-ff0e8400-e29b-41d4-a716-446655440000",
"retryMode": "resume",
"retryNumber": 1,
"resumeFromPhase": "Machine Learning Analysis",
"status": "Initiated",
"estimatedDuration": "20-25 minutes",
"estimatedCompletion": "2024-01-20T12:30:00Z",
"preservedResults": {
"phasesPreserved": 2,
"recordsProcessed": 187248,
"progressSaved": 45
},
"resourcesAllocated": {
"cpuUnits": 6,
"memoryGB": 12,
"estimatedCost": "$3.20"
},
"retryAttemptDate": "2024-01-20T12:05:00Z"
}
Soumettre des Opérations en Lot
POST /api/{tenantId}/{projectId}/async/batch
Soumet plusieurs opérations asynchrones en lot avec dépendances et coordination. Utile pour des workflows complexes nécessitant plusieurs opérations interconnectées.
Corps de la requête
{
"batchName": "Monthly Process Mining Pipeline",
"batchDescription": "Complete monthly analysis workflow with multiple datasets",
"operations": [
{
"operationName": "Data Preparation",
"operationType": "DataEnrichment",
"priority": "High",
"operationKey": "data-prep",
"parameters": {
"datasetId": "dataset-1",
"cleaningRules": ["remove_duplicates", "fix_timestamps"],
"outputFormat": "processed_csv"
}
},
{
"operationName": "Process Discovery",
"operationType": "ProcessMiningAnalysis",
"priority": "High",
"operationKey": "discovery",
"dependencies": ["data-prep"],
"parameters": {
"algorithm": "alpha_miner_enhanced",
"enableVariantAnalysis": true
}
},
{
"operationName": "Performance Analysis",
"operationType": "ProcessMiningAnalysis",
"priority": "Normal",
"operationKey": "performance",
"dependencies": ["discovery"],
"parameters": {
"enableBottleneckDetection": true,
"generateOptimizationRecommendations": true
}
}
],
"batchCallbacks": {
"onBatchStart": "https://your-app.com/webhooks/batch-start",
"onOperationComplete": "https://your-app.com/webhooks/operation-complete",
"onBatchComplete": "https://your-app.com/webhooks/batch-complete"
},
"failurePolicy": {
"stopOnFirstFailure": false,
"continueIndependentOperations": true,
"retryFailedOperations": true
}
}
Réponse
{
"batchId": "batch-567e8400-e29b-41d4-a716-446655440000",
"batchName": "Monthly Process Mining Pipeline",
"status": "Initiated",
"operations": [
{
"operationKey": "data-prep",
"operationId": "op-prep-890e8400-e29b-41d4-a716-446655440000",
"status": "Running",
"dependencies": [],
"estimatedDuration": "15 minutes"
},
{
"operationKey": "discovery",
"operationId": "op-disc-901e8400-e29b-41d4-a716-446655440000",
"status": "Pending",
"dependencies": ["data-prep"],
"estimatedStartTime": "2024-01-20T12:20:00Z"
},
{
"operationKey": "performance",
"operationId": "op-perf-012e8400-e29b-41d4-a716-446655440000",
"status": "Pending",
"dependencies": ["discovery"],
"estimatedStartTime": "2024-01-20T12:45:00Z"
}
],
"totalOperations": 3,
"estimatedBatchDuration": "75-90 minutes",
"estimatedBatchCompletion": "2024-01-20T13:45:00Z",
"batchStartTime": "2024-01-20T12:05:00Z",
"trackingUrl": "/api/{tenantId}/{projectId}/async/batch/batch-567e8400-e29b-41d4-a716-446655440000"
}
Exemple : Workflow Complet d'Opération Asynchrone
Cet exemple montre le cycle de vie complet des opérations asynchrones :
// 1. Enregistrer un webhook pour les notifications en temps réel
const registerWebhook = async () => {
const response = await fetch('/api/{tenantId}/{projectId}/async/webhooks', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`
},
body: JSON.stringify({
webhookUrl: 'https://your-app.com/webhooks/async-operations',
webhookName: 'Process Mining Webhook',
events: [
'operation.started',
'operation.progress',
'operation.completed',
'operation.failed'
],
filters: {
operationTypes: ['ProcessMiningAnalysis'],
priorities: ['High', 'Critical'],
minProgressIncrement: 15
},
authentication: {
type: 'hmac-sha256',
secret: 'your-secret-key'
}
})
});
return await response.json();
};
// 2. Démarrer une opération asynchrone complexe
const startAsyncAnalysis = async () => {
const response = await fetch('/api/{tenantId}/{projectId}/async/operation', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`
},
body: JSON.stringify({
operationType: 'ProcessMiningAnalysis',
operationName: 'Advanced Customer Journey Analysis',
operationDescription: 'Deep ML-powered analysis with anomaly detection',
priority: 'High',
parameters: {
datasetId: '880e8400-e29b-41d4-a716-446655440000',
analysisType: 'comprehensive',
timeWindow: {
startDate: '2024-01-01',
endDate: '2024-01-31'
},
algorithmSettings: {
useAdvancedML: true,
enableAnomalyDetection: true,
performanceOptimization: 'high_accuracy'
},
outputOptions: {
generateReports: true,
createVisualizations: true,
exportFormats: ['PDF', 'CSV', 'JSON']
}
},
callbacks: {
onProgress: 'https://your-app.com/webhooks/progress',
onCompletion: 'https://your-app.com/webhooks/completion',
onError: 'https://your-app.com/webhooks/error'
},
notifications: {
email: ['analyst@company.com'],
slack: {
channel: '#process-mining',
mentionUsers: ['@analyst']
}
},
timeout: 7200
})
});
return await response.json();
};
// 3. Surveiller la progression de l'opération
const monitorOperation = async (operationId) => {
const checkStatus = async () => {
const response = await fetch(`/api/{tenantId}/{projectId}/async/operation/${operationId}`, {
headers: {
'Authorization': `Bearer ${token}`
}
});
const operation = await response.json();
console.log(`Operation ${operationId}: ${operation.status} (${operation.progress.percentage}%)`);
console.log(`Phase actuelle : ${operation.progress.currentPhase}`);
console.log(`ETA : ${operation.progress.estimatedCompletion}`);
if (operation.status === 'Running') {
setTimeout(() => checkStatus(), 60000); // Vérifier chaque minute
} else if (operation.status === 'Completed') {
console.log('Opération terminée avec succès !');
await getOperationResults(operationId);
} else if (operation.status === 'Failed') {
console.log('Échec de l’opération, tentative de relance...');
await retryOperation(operationId);
}
};
await checkStatus();
};
// 4. Obtenir les résultats de l'opération
const getOperationResults = async (operationId) => {
const response = await fetch(`/api/{tenantId}/{projectId}/async/operation/${operationId}/results?format=detailed&includeArtifacts=true`, {
headers: {
'Authorization': `Bearer ${token}`
}
});
const results = await response.json();
console.log('Résultats de l’opération :', results.summary);
console.log('Artefacts générés :');
results.artifacts.forEach(artifact => {
console.log(`- ${artifact.name} (${artifact.format}) : ${artifact.downloadUrl}`);
});
return results;
};
// 5. Relancer une opération échouée
const retryOperation = async (operationId) => {
const response = await fetch(`/api/{tenantId}/{projectId}/async/operation/${operationId}/retry`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`
},
body: JSON.stringify({
retryMode: 'resume',
retryReason: 'Automatic retry with increased resources',
modifyParameters: true,
updatedParameters: {
resourceAllocation: {
cpuUnits: 6,
memoryGB: 12,
priority: 'Critical'
}
},
newTimeout: 10800
})
});
const retryResult = await response.json();
console.log(`Relance de l’opération lancée : ${retryResult.newOperationId}`);
// Surveiller la relance de l'opération
await monitorOperation(retryResult.newOperationId);
return retryResult;
};
// 6. Soumettre des opérations en lot
const submitBatchOperations = async () => {
const response = await fetch('/api/{tenantId}/{projectId}/async/batch', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`
},
body: JSON.stringify({
batchName: 'Complete Process Mining Pipeline',
batchDescription: 'End-to-end analysis with data prep and reporting',
operations: [
{
operationName: 'Data Cleaning',
operationType: 'DataEnrichment',
priority: 'High',
operationKey: 'clean',
parameters: {
datasetId: 'raw-dataset-123',
cleaningRules: ['remove_duplicates', 'fix_timestamps', 'validate_activities']
}
},
{
operationName: 'Process Analysis',
operationType: 'ProcessMiningAnalysis',
priority: 'High',
operationKey: 'analyze',
dependencies: ['clean'],
parameters: {
analysisType: 'comprehensive',
enableML: true,
generateInsights: true
}
},
{
operationName: 'Report Generation',
operationType: 'ReportGeneration',
priority: 'Normal',
operationKey: 'report',
dependencies: ['analyze'],
parameters: {
reportType: 'executive_summary',
includeVisualizations: true,
exportFormats: ['PDF', 'PowerPoint']
}
}
],
failurePolicy: {
stopOnFirstFailure: false,
continueIndependentOperations: true,
retryFailedOperations: true
}
})
});
return await response.json();
};
// Exécuter le workflow complet asynchrone
const runAsyncWorkflow = async () => {
try {
console.log('Démarrage du workflow d’opération asynchrone...');
// Enregistrer le webhook
const webhook = await registerWebhook();
console.log(`Webhook enregistré : ${webhook.webhookId}`);
// Démarrer l'opération
const operation = await startAsyncAnalysis();
console.log(`Opération démarrée : ${operation.operationId}`);
console.log(`Fin estimée : ${operation.estimatedCompletion}`);
// Surveiller la progression
await monitorOperation(operation.operationId);
} catch (error) {
console.error('Échec du workflow asynchrone :', error);
}
};
// Démarrer le workflow
runAsyncWorkflow();
Exemple Python
import requests
import time
import json
import hmac
import hashlib
from datetime import datetime, timedelta
class AsyncOperationManager:
def __init__(self, base_url, tenant_id, project_id, token):
self.base_url = base_url
self.tenant_id = tenant_id
self.project_id = project_id
self.headers = {
'Authorization': f'Bearer {token}',
'Content-Type': 'application/json'
}
def start_operation(self, operation_type, name, parameters, priority='Normal', timeout=3600):
"""Démarrer une opération asynchrone"""
url = f"{self.base_url}/api/{self.tenant_id}/{self.project_id}/async/operation"
payload = {
'operationType': operation_type,
'operationName': name,
'priority': priority,
'parameters': parameters,
'timeout': timeout,
'callbacks': {
'onProgress': 'https://your-app.com/webhooks/progress',
'onCompletion': 'https://your-app.com/webhooks/completion',
'onError': 'https://your-app.com/webhooks/error'
}
}
response = requests.post(url, json=payload, headers=self.headers)
return response.json()
def get_operation_status(self, operation_id):
"""Obtenir le statut actuel de l'opération"""
url = f"{self.base_url}/api/{self.tenant_id}/{self.project_id}/async/operation/{operation_id}"
response = requests.get(url, headers=self.headers)
return response.json()
def list_operations(self, status=None, operation_type=None, page=1, page_size=20):
"""Lister les opérations asynchrones avec filtrage"""
url = f"{self.base_url}/api/{self.tenant_id}/{self.project_id}/async/operations"
params = {'page': page, 'pageSize': page_size}
if status:
params['status'] = status
if operation_type:
params['operationType'] = operation_type
response = requests.get(url, params=params, headers=self.headers)
return response.json()
def cancel_operation(self, operation_id, reason="User cancellation"):
"""Annuler une opération en cours"""
url = f"{self.base_url}/api/{self.tenant_id}/{self.project_id}/async/operation/{operation_id}"
payload = {
'reason': reason,
'preservePartialResults': True,
'notifyCallbacks': True
}
response = requests.delete(url, json=payload, headers=self.headers)
return response.json()
def get_operation_results(self, operation_id, format_type='detailed', include_artifacts=True):
"""Obtenir les résultats de l'opération"""
url = f"{self.base_url}/api/{self.tenant_id}/{self.project_id}/async/operation/{operation_id}/results"
params = {
'format': format_type,
'includeArtifacts': str(include_artifacts).lower()
}
response = requests.get(url, params=params, headers=self.headers)
return response.json()
def retry_operation(self, operation_id, retry_mode='resume', updated_params=None):
"""Relancer une opération échouée"""
url = f"{self.base_url}/api/{self.tenant_id}/{self.project_id}/async/operation/{operation_id}/retry"
payload = {
'retryMode': retry_mode,
'retryReason': 'Automatic retry with optimization',
'modifyParameters': updated_params is not None
}
if updated_params:
payload['updatedParameters'] = updated_params
response = requests.post(url, json=payload, headers=self.headers)
return response.json()
def register_webhook(self, webhook_url, events, filters=None):
"""Enregistrer un webhook pour les notifications d'opération"""
url = f"{self.base_url}/api/{self.tenant_id}/{self.project_id}/async/webhooks"
payload = {
'webhookUrl': webhook_url,
'webhookName': 'Python SDK Webhook',
'events': events,
'filters': filters or {},
'authentication': {
'type': 'hmac-sha256',
'secret': 'your-webhook-secret'
}
}
response = requests