MCPcopy Create free account
hub / github.com/serverless/examples / generateInvocations

Function generateInvocations

aws-node-fullstack/frontend/src/DemoApp.js:170–214  ·  view source on GitHub ↗

* Generate Invocations

(event)

Source from the content-addressed store, hash-verified

168 */
169
170 generateInvocations(event) {
171
172 event.preventDefault()
173
174 const self = this
175
176 let invocations = this.refInputInvocations.current.value || this.state.admin.invocations
177 invocations = parseInt(invocations) || 0
178
179 if (invocations > 999) {
180 //eslint-disable-next-line
181 const r = confirm(`\nThis will generate ${invocations} API requests. Are you sure you want to do this?\n`)
182 if (!r) return
183 }
184
185 // Call API Function
186 const callApi = () => {
187 return fetch(this.state.admin.url, {
188 method: 'POST',
189 mode: 'cors',
190 headers: {
191 'Content-Type': 'application/json',
192 },
193 body: JSON.stringify({
194 name: 'Sample Invocation',
195 email: 'sample@invocations.com'
196 }),
197 })
198 }
199
200 // Runner Function
201 const runner = async (cb) => {
202 let array = []
203 for (let i = 0; i <= invocations; i++) { array.push(i) }
204 for (const item of array) {
205 await callApi()
206 self.setStatus(`Performing API request ${item}/${invocations}...`)
207 }
208 if (cb) return cb()
209 }
210
211 runner(() => {
212 self.setStatus(`Successfully completed ${invocations} requests!`)
213 })
214 }
215
216 /**
217 * Generate Random Error

Callers

nothing calls this directly

Calls 2

parseIntFunction · 0.85
runnerFunction · 0.85

Tested by

no test coverage detected