Skip to content

Instantly share code, notes, and snippets.

@tardieu
Last active June 21, 2021 13:32
Show Gist options
  • Save tardieu/491b189c78e0c9487875fd4a69017f6b to your computer and use it in GitHub Desktop.
Save tardieu/491b189c78e0c9487875fd4a69017f6b to your computer and use it in GitHub Desktop.
aapl.py - actor
@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