mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-05 23:43:07 +00:00
Added events and requests for support. Reworked delivery_monitor into a featured devlivery_service, that - supports relay publish and lightpush depending on configuration but with fallback options - if available and configured it utilizes store api to confirm message delivery - emits message delivery events accordingly Notice: There are parts still in WIP and needs review and follow ups. prepare for use in api_example
33 lines
1019 B
Nim
33 lines
1019 B
Nim
import chronos
|
|
import ./delivery_task
|
|
|
|
type BaseSendProcessor* = ref object of RootObj
|
|
fallbackProcessor*: BaseSendProcessor
|
|
|
|
proc chain*(self: BaseSendProcessor, next: BaseSendProcessor) =
|
|
self.fallbackProcessor = next
|
|
|
|
method isValidProcessor*(
|
|
self: BaseSendProcessor, task: DeliveryTask
|
|
): Future[bool] {.async, base.} =
|
|
return false
|
|
|
|
method sendImpl*(
|
|
self: BaseSendProcessor, task: DeliveryTask
|
|
): Future[void] {.async, base.} =
|
|
assert false, "Not implemented"
|
|
|
|
method process*(
|
|
self: BaseSendProcessor, task: DeliveryTask
|
|
): Future[void] {.async, base.} =
|
|
var currentProcessor: BaseSendProcessor = self
|
|
var keepTrying = true
|
|
while not currentProcessor.isNil() and keepTrying:
|
|
if await currentProcessor.isValidProcessor(task):
|
|
await currentProcessor.sendImpl(task)
|
|
currentProcessor = currentProcessor.fallbackProcessor
|
|
keepTrying = task.state == DeliveryState.FallbackRetry
|
|
|
|
if task.state == DeliveryState.FallbackRetry:
|
|
task.state = DeliveryState.NextRoundRetry
|