Last active
October 2, 2022 10:25
-
-
Save ibrahimsn98/6d3e9df9b75fd276bae1ae972c48111e to your computer and use it in GitHub Desktop.
ty-demeter-blog-6
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
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