Last active
June 21, 2021 13:32
-
-
Save tardieu/491b189c78e0c9487875fd4a69017f6b to your computer and use it in GitHub Desktop.
aapl.py - actor
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
@ray.remote | |
class Comparator: | |
def __init__(self): | |
self.last_quote = None | |
def append(self, event): | |
payload = json.loads(event) # parse event payload to json | |
quote = payload[0]['price'] # extract AAPL quote | |
if self.last_quote: | |
if quote > self.last_quote: | |
sink.append('AAPL is up') # send to Slack | |
elif quote < self.last_quote: | |
sink.append('AAPL is down') # send to Slack | |
self.last_quote = quote | |
comparator = Comparator.remote() # instantiate comparator actor | |
source.send_to(comparator) # subscribe comparator to source |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment