Skip to content

Instantly share code, notes, and snippets.

@ibrahimsn98
Last active October 2, 2022 10:25
Show Gist options
  • Save ibrahimsn98/6d3e9df9b75fd276bae1ae972c48111e to your computer and use it in GitHub Desktop.
Save ibrahimsn98/6d3e9df9b75fd276bae1ae972c48111e to your computer and use it in GitHub Desktop.
ty-demeter-blog-6
internal class BatchEventOperation : Operation {
override suspend fun operate(demeter: Demeter) {
val events = demeter.eventDataProvider.fetchAwaitingEvents(FETCH_EVENT_SIZE)
...
demeter.eventDataProvider.updateEventStatus(
events = events,
eventStatus = EventStatus.PROCESSING,
)
val eventRequest = BatchEventRequest.newEventRequest(
baseUrl = demeter.baseUrl,
payloads = events,
converterFactory = demeter.converterFactory,
)
val eventCall = RealEventCall.newEventCall(demeter.httpClient, eventRequest)
val callResult = eventCall.enqueue()
if (callResult.isSuccess) {
demeter.eventDataProvider.deleteEvents(events)
demeter.eventResultReporter.report(callResult)
} else {
demeter.eventDataProvider.updateEventStatus(EventStatus.AWAITING, events)
demeter.eventResultReporter.report(callResult)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment