-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscheduler.rb
39 lines (35 loc) · 988 Bytes
/
scheduler.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
def ping(event:, context:)
require 'net/http'
uri = URI('https://data.exchange.coinjar.com/products/BTCAUD/ticker')
response = Net::HTTP.get_response(uri)
if response.code == '200'
require 'json'
body = JSON.parse(response.body)
tick = {
currency_pair: 'BTCAUD',
current_time: body.fetch('current_time'),
last: body.fetch('last'),
bid: body.fetch('bid'),
ask: body.fetch('ask')
}.to_json
puts "tick=#{tick}"
else
puts "code=#{response.code}"
end
end
def iterate(event:, context:)
idx = event.dig('iterator', 'index') + 1
puts "idx=#{idx}"
require 'aws-sdk-lambda'
client = Aws::Lambda::Client.new(region: ENV.fetch('REGION'))
resp = client.invoke({
function_name: "lambda-scheduler-#{ENV.fetch('STAGE')}-ping",
invocation_type: 'Event',
payload: { index: idx }.to_json
})
{
index: idx,
continue: idx < event.dig('iterator', 'count'),
count: event.dig('iterator', 'count')
}
end