/** * Invokes a function. * * @param fnInvokeClient the service client to use to delete the Function. * @param function the Function to invoke. * @param payload the payload to pass to the function. */ private static async Task <string> InvokeFunction(FunctionsInvokeClient fnInvokeClient, FunctionSummary function, string payload) { string response = null; try { logger.Info($"Invoking function endpoint: {function.InvokeEndpoint}"); // Configure the client to use the assigned function endpoint. fnInvokeClient.SetEndpoint(function.InvokeEndpoint); var invokeFunctionRequest = new InvokeFunctionRequest { FunctionId = function.Id, InvokeFunctionBody = GenerateStreamFromString(payload) }; // Invoke the function var invokeFunctionResponse = await fnInvokeClient.InvokeFunction(invokeFunctionRequest); // Handle the response response = new StreamReader(invokeFunctionResponse.InputStream).ReadToEnd(); } catch (Exception e) { logger.Error($"Failed to invoke function: {e}"); } return(response); }
/** * Invoke a function. * * @param provider the OCI credentials provider. * @param compartmentId the compartment in which to created the required * resources. * @param payload the payload to be sent to the function on invocation. */ private static async Task InvokeFunction(IBasicAuthenticationDetailsProvider provider, string compartmentId, string payload) { var fnManagementClient = new FunctionsManagementClient(provider); var fnInvokeClient = new FunctionsInvokeClient(provider); try { // Invoke the function var fn = await GetUniqueFunctionByName(fnManagementClient, compartmentId); var response = await InvokeFunction(fnInvokeClient, fn, payload); if (response != null) { logger.Info($"Response from function: {response}"); } } catch (Exception e) { logger.Error($"Failed to invoke function: {e}"); } finally { fnInvokeClient.Dispose(); fnManagementClient.Dispose(); } }
protected override void ProcessRecord() { base.ProcessRecord(); client?.Dispose(); client = new FunctionsInvokeClient(AuthProvider, new Oci.Common.ClientConfiguration { RetryConfiguration = retryConfig, TimeoutMillis = TimeOutInMillis, ClientUserAgent = PSUserAgent }); try { WriteDebug("Choosing Endpoint:" + Endpoint); client.SetEndpoint(Endpoint); } catch (Exception ex) { TerminatingErrorDuringExecution(ex); } }
protected override void ProcessRecord() { base.ProcessRecord(); try { client?.Dispose(); int timeout = GetPreferredTimeout(); WriteDebug($"Cmdlet Timeout : {timeout} milliseconds."); client = new FunctionsInvokeClient(AuthProvider, new Oci.Common.ClientConfiguration { RetryConfiguration = retryConfig, TimeoutMillis = timeout, ClientUserAgent = PSUserAgent }); WriteDebug("Choosing Endpoint:" + Endpoint); client.SetEndpoint(Endpoint); } catch (Exception ex) { TerminatingErrorDuringExecution(ex); } }