Hay más ejemplos de AWS SDK disponibles en el GitHub repositorio de ejemplos de AWS Doc SDK.
Las traducciones son generadas a través de traducción automática. En caso de conflicto entre la traducción y la version original de inglés, prevalecerá la version en inglés.
StartMatchingJobÚselo con un AWS SDK
Los siguientes ejemplos de código muestran cómo utilizar StartMatchingJob.
Los ejemplos de acciones son extractos de código de programas más grandes y deben ejecutarse en contexto. Puede ver esta acción en contexto en el siguiente ejemplo de código:
- Java
-
- SDK para Java 2.x
-
/**
* Starts a matching job asynchronously for the specified workflow name.
*
* @param workflowName the name of the workflow for which to start the matching job
* @return a {@link CompletableFuture} that completes with the job ID of the started matching job, or an empty
* string if the operation fails
*/
public CompletableFuture<String> startMatchingJobAsync(String workflowName) {
StartMatchingJobRequest jobRequest = StartMatchingJobRequest.builder()
.workflowName(workflowName)
.build();
return getResolutionAsyncClient().startMatchingJob(jobRequest)
.whenComplete((response, exception) -> {
if (response != null) {
String jobId = response.jobId();
logger.info("Job ID: " + jobId);
} else {
if (exception == null) {
throw new CompletionException("An unknown error occurred while starting the job.", null);
}
Throwable cause = exception.getCause();
if (cause instanceof ConflictException) {
throw new CompletionException("The job is already running. Resolve conflicts before starting a new job.", cause);
}
// Wrap other AWS exceptions in a CompletionException.
throw new CompletionException("Failed to start the job: " + exception.getMessage(), exception);
}
})
.thenApply(response -> response != null ? response.jobId() : "");
}
- JavaScript
-
- SDK para JavaScript (v3)
-
//The default inputs for this demo are read from the ../inputs.json.
import { fileURLToPath } from "node:url";
import {
StartMatchingJobCommand,
EntityResolutionClient,
} from "@aws-sdk/client-entityresolution";
import data from "../inputs.json" with { type: "json" };
const region = "eu-west-1";
const erClient = new EntityResolutionClient({ region: region });
export const main = async () => {
const matchingJobOfWorkflowParams = {
workflowName: `${data.inputs.workflowName}`,
};
try {
const command = new StartMatchingJobCommand(matchingJobOfWorkflowParams);
const response = await erClient.send(command);
console.log(`Job ID: ${response.jobID} \n
The matching job was successfully started.`);
} catch (caught) {
console.error(caught.message);
throw caught;
}
};