@@ -59,7 +59,9 @@ program: |
5959 }
6060 }).do_request().as(resp, resp.StatusCode == 200
6161 ?
62- bytes(resp.Body).decode_json().as(body,
62+ // Response is successful, but did we get any data?
63+ bytes(resp.Body).decode_json().as(body, has(body.instances) && size(body.instances) > 0
64+ ?
6365 {
6466 "events": body.instances.map(instance, instance.product_line_items.map(line_item,
6567 {
@@ -73,17 +75,40 @@ program: |
7375 })
7476 }
7577 }
76- )).flatten(), // Pass line_items as events, with added info
78+ )).flatten(), // Pass line_items as events, with added info
7779 "cursor": {
7880 "last_to": state.to
7981 },
8082 // Are we more than 1 day behind?
8183 "want_more": state.to.parse_time(time_layout.RFC3339) < now() - duration("24h"),
8284 "api_key": state.api_key,
83- "organization_id": state.organization_id
85+ "organization_id": state.organization_id,
86+ }
87+ :
88+ // We don't have any data, but we still need to return an event
89+ // Otherwise the "want_more" logic will not work
90+ {
91+ "events": [{
92+ "ess": {
93+ "billing": {
94+ "organization_id": state.organization_id,
95+ "from": state.from,
96+ "to": state.to,
97+ "total_ecu": 0,
98+ }
99+ }
100+ }],
101+ "cursor": {
102+ "last_to": state.to
103+ },
104+ // Are we more than 1 day behind?
105+ "want_more": state.to.parse_time(time_layout.RFC3339) < now() - duration("24h"),
106+ "api_key": state.api_key,
107+ "organization_id": state.organization_id,
84108 }
85109 )
86110 :
111+ // Response was not successful, return an error event
87112 {
88113 "events": {
89114 "error": {
@@ -102,7 +127,7 @@ program: |
102127 },
103128 "want_more": state.to.parse_time(time_layout.RFC3339) < now() - duration("24h"),
104129 "api_key": state.api_key,
105- "organization_id": state.organization_id
130+ "organization_id": state.organization_id,
106131 }
107132 )
108133 )
0 commit comments