本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
執行排程查詢
您可以使用下列程式碼片段來執行排程查詢。
- 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 := ×treamquery.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
-
下列程式碼片段使用 AWS SDK適用於 JavaScript V2 樣式的 。它以 Node.js 範例應用程式為基礎,適用於 上的 LiveAnalytics 應用程式 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; } }
描述排程查詢
更新排程查詢