Ejecutar consulta programada - Amazon Timestream

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.

Ejecutar consulta programada

Puede usar los siguientes fragmentos de código para ejecutar una consulta programada.

Java
public void executeScheduledQueries(String scheduledQueryArn, Date invocationTime) { System.out.println("Executing Scheduled Query"); try { ExecuteScheduledQueryResult executeScheduledQueryResult = queryClient.executeScheduledQuery(new ExecuteScheduledQueryRequest() .withScheduledQueryArn(scheduledQueryArn) .withInvocationTime(invocationTime) ); } catch (ResourceNotFoundException e) { System.out.println("Scheduled Query doesn't exist"); throw e; } catch (Exception e) { System.out.println("Execution Scheduled Query failed: " + e); throw e; } }
Java v2
public void executeScheduledQuery(String scheduledQueryArn) { System.out.println("Executing Scheduled Query"); try { ExecuteScheduledQueryResponse executeScheduledQueryResult = queryClient.executeScheduledQuery(ExecuteScheduledQueryRequest.builder() .scheduledQueryArn(scheduledQueryArn) .invocationTime(Instant.now()) .build() ); System.out.println("Execute ScheduledQuery response code: " + executeScheduledQueryResult.sdkHttpResponse().statusCode()); } catch (ResourceNotFoundException e) { System.out.println("Scheduled Query doesn't exist"); throw e; } catch (Exception e) { System.out.println("Execution Scheduled Query failed: " + e); throw e; } }
Go
func (timestreamBuilder TimestreamBuilder) ExecuteScheduledQuery(scheduledQueryArn string, invocationTime time.Time) error { executeScheduledQueryInput := &timestreamquery.ExecuteScheduledQueryInput{ ScheduledQueryArn: aws.String(scheduledQueryArn), InvocationTime: aws.Time(invocationTime), } executeScheduledQueryOutput, err := timestreamBuilder.QuerySvc.ExecuteScheduledQuery(executeScheduledQueryInput) if err != nil { if aerr, ok := err.(awserr.Error); ok { switch aerr.Code() { case timestreamquery.ErrCodeResourceNotFoundException: fmt.Println(timestreamquery.ErrCodeResourceNotFoundException, aerr.Error()) default: fmt.Printf("Error: %s", aerr.Error()) } } else { fmt.Printf("Error: %s", err.Error()) } return err } else { fmt.Println("ExecuteScheduledQuery is successful, below is the output:") fmt.Println(executeScheduledQueryOutput.GoString()) return nil } }
Python
def execute_scheduled_query(self, scheduled_query_arn, invocation_time): print("\nExecuting Scheduled Query") try: self.query_client.execute_scheduled_query(ScheduledQueryArn=scheduled_query_arn, InvocationTime=invocation_time) print("Successfully started executing scheduled query") except self.query_client.exceptions.ResourceNotFoundException as err: print("Scheduled Query doesn't exist") raise err except Exception as err: print("Scheduled Query execution failed:", err) raise err
Node.js

En el siguiente fragmento se utiliza el estilo for V2. AWS SDK JavaScript Se basa en la aplicación de ejemplo de Node.js, ejemplo de Amazon Timestream LiveAnalytics para su aplicación en. GitHub

async function executeScheduledQuery(scheduledQueryArn, invocationTime) { console.log("Executing Scheduled Query"); var params = { ScheduledQueryArn: scheduledQueryArn, InvocationTime: invocationTime } try { await queryClient.executeScheduledQuery(params).promise(); } catch (err) { console.log("Execute Scheduled Query failed: ", err); throw err; } }
.NET
private async Task ExecuteScheduledQuery(string scheduledQueryArn, DateTime invocationTime) { try { Console.WriteLine("Running Scheduled Query"); await _amazonTimestreamQuery.ExecuteScheduledQueryAsync(new ExecuteScheduledQueryRequest() { ScheduledQueryArn = scheduledQueryArn, InvocationTime = invocationTime }); Console.WriteLine("Successfully started manual run of scheduled query"); } catch (ResourceNotFoundException e) { Console.WriteLine($"Scheduled Query doesn't exist: {e}"); throw; } catch (Exception e) { Console.WriteLine($"Execute Scheduled Query failed: {e}"); throw; } }