Daml dit if Timed Events

Hello all,

I was reading the documentation on daml dit if regarding IntegrationTimeEvents, and it left me wondering if it would be possible to leverage it to schedule events at a fixed point in time, for example, running the event every day at midnight.
If not how would you advise me to best use this library (or others) to achieve this.

Thank you in advance.

The only native support for timing within daml-dit-if is through periodic timed events.

https://github.com/digital-asset/daml-dit-if/blob/7a529fc90d75d3f6f53bce748d0b52749f682291/daml_dit_if/api/__init__.py#L70

This decorator requests that the framework issue a request to run the associated event handler at the specified interval. No strong guarantees are made about exact timing.

However, this is where daml-dit-if's support for internal queuing comes into play:

https://github.com/digital-asset/daml-dit-if/blob/7a529fc90d75d3f6f53bce748d0b52749f682291/daml_dit_if/api/__init__.py#L55

One of the primary motivations behind queuing is to allow daml-dit-if to support integrations with components for which it has no direct support. As you mention in the Slack thread, there are libraries like aioschedule that do provide more time based scheduling support.

Queues can enable you to use these. The basic pattern to follow is the same pattern used in the Timer integration within the core pack:

There is one event handler for a queue event, and another process that drops events on the queue at the appropriate time. For the timer integration linked above, the timing the timing is managed by the interval timer built into daml-dit-if, but there is nothing that would prevent the use of aioschedule or similar.

Another aspect that you’ll need to be aware of is that for aioschedule to work, it appears to need to run an asyncio coroutine. These can be passed to daml-dit-if to run by returning them from the entrypoint function:

There’s an example of how that works in the Exberry integration (which is designed with a background coroutine to manage a connection):

Hello @Michael_Schaeffer, the indications you have provided have indeed been helpful, but now I’m facing a different issue, which is, when starting the integration first the first time (so the .ddit-venv hasn’t been created yet), I get the following error regarding the aioschedule module.

ERROR: Could not find a version that satisfies the requirement aioschedule==0.5.2 (from -r requirements.txt (line 2)) (from versions: none)
ERROR: No matching distribution found for aioschedule==0.5.2 (from -r requirements.txt (line 2))

As a quick fix I just go inside the env and install it manually, but that won’t work to start it on docker containers, for example. Do you know of a way to fix this?

Thanks