# Daml dit if Timed Events

**URL:** <https://forum.canton.network/t/daml-dit-if-timed-events/4204>\
**Category:** App Development\
**Tags:** daml, damlhub\
**Created:** [March 27, 2022, 11:00pm UTC](https://forum.canton.network/t/daml-dit-if-timed-events/4204 "2022-03-27T23:00:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Martins](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/david_martins/32/1792_2.png) [@David\_Martins](https://forum.canton.network/u/David_Martins)\
**Post date:** [March 27, 2022, 11:00pm UTC](https://forum.canton.network/t/daml-dit-if-timed-events/4204/1 "2022-03-27T23:00:36Z")

</div>

Hello all,

I was reading the documentation on daml dit if regarding [IntegrationTimeEvents](https://github.com/digital-asset/daml-dit-if#timer-events), 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.

---

<div class="post-metadata">

**Author:** ![Michael\_Schaeffer](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/michael_schaeffer/32/503_2.png) [@Michael\_Schaeffer](https://forum.canton.network/u/Michael_Schaeffer)\
**Post date:** [March 29, 2022, 10:32am UTC](https://forum.canton.network/t/daml-dit-if-timed-events/4204/2 "2022-03-29T10:32:25Z")

</div>

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](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](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.

> **[aioschedule](https://pypi.org/project/aioschedule/)**
>
> Job scheduling for humans.

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:

> <https://github.com/digital-asset/daml-dit-integration-core/blob/7b50d3af80ee93f1289a1e6594b2ff7bbffbe5d4/src/core_int/integration_timer.py#L48>

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):

> <https://github.com/digital-asset/daml-dit-integration-exberry/blob/5a490df3f4e51c0402642a39a55b807c740524c3/src/exberry_int/main.py#L198>

---

<div class="post-metadata">

**Author:** ![David\_Martins](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/david_martins/32/1792_2.png) [@David\_Martins](https://forum.canton.network/u/David_Martins)\
**Post date:** [April 14, 2022, 12:23pm UTC](https://forum.canton.network/t/daml-dit-if-timed-events/4204/3 "2022-04-14T12:23:23Z")

</div>

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.

```haskell
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
