-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #176 from dispatchrun/aiohttp-2
interoperability with asyncio (part 3): refactor with aiohttp
- Loading branch information
Showing
62 changed files
with
2,579 additions
and
3,465 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import random | ||
|
||
import requests | ||
|
||
import dispatch | ||
import dispatch.integrations.requests | ||
|
||
rng = random.Random(2) | ||
|
||
|
||
def third_party_api_call(x): | ||
# Simulate a third-party API call that fails. | ||
print(f"Simulating third-party API call with {x}") | ||
if x < 3: | ||
print("RAISE EXCEPTION") | ||
raise requests.RequestException("Simulated failure") | ||
else: | ||
return "SUCCESS" | ||
|
||
|
||
# Use the `dispatch.function` decorator to declare a stateful function. | ||
@dispatch.function | ||
def auto_retry(): | ||
x = rng.randint(0, 5) | ||
return third_party_api_call(x) | ||
|
||
|
||
if __name__ == "__main__": | ||
print(dispatch.run(auto_retry())) |
Empty file.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import requests | ||
|
||
import dispatch | ||
|
||
|
||
@dispatch.function | ||
def publish(url, payload): | ||
r = requests.post(url, data=payload) | ||
r.raise_for_status() | ||
return r.text | ||
|
||
|
||
@dispatch.function | ||
async def getting_started(): | ||
return await publish("https://httpstat.us/200", {"hello": "world"}) | ||
|
||
|
||
if __name__ == "__main__": | ||
print(dispatch.run(getting_started())) |
Empty file.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.