# Data freshness for events and problems

**URL:** <https://community.dynatrace.com/t/data-freshness-for-events-and-problems/46735>\
**Category:** Automations\
**Tags:** workflows, automations\
**Created:** [July 22, 2024, 2:39pm UTC](https://community.dynatrace.com/t/data-freshness-for-events-and-problems/46735 "2024-07-22T14:39:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![henk\_stobbe](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/henk_stobbe/32/30434_2.png) [@henk\_stobbe](https://community.dynatrace.com/u/henk_stobbe)\
**Post date:** [July 22, 2024, 2:39pm UTC](https://community.dynatrace.com/t/data-freshness-for-events-and-problems/46735/1 "2024-07-22T14:39:52Z")

</div>

Hello,

Who can confirm below?

When using a “event” or “problem” trigger in a workflow, why does it take 5 minutes for you can retrieve by DQL:

Events belonging to a Problem

Problem belonging to an Event

For my workflow needed to wait 3x 1:59 minutes to make it work (timeout per task is 2:00 min)k

KR Henk

---

<div class="post-metadata">

**Author:** ![christian\_kreuz](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/christian_kreuz/32/21669_2.png) [@christian\_kreuz](https://community.dynatrace.com/u/christian_kreuz)\
**Post date:** [July 25, 2024, 8:55am UTC](https://community.dynatrace.com/t/data-freshness-for-events-and-problems/46735/2 "2024-07-25T08:55:25Z")

</div>

Hi,

there is a slight delay between when Workflows are triggered (by an event), and when data is available in Grail to be fetched.

Though I’ve never seen a delay above 30 seconds. Could you share the DQL Statements that you’re using to fetch those events / problems? Are you using the DQL Action, or writing JavaScript Code?

---

<div class="post-metadata">

**Author:** ![henk\_stobbe](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/henk_stobbe/32/30434_2.png) [@henk\_stobbe](https://community.dynatrace.com/u/henk_stobbe)\
**Post date:** [July 25, 2024, 9:15am UTC](https://community.dynatrace.com/t/data-freshness-for-events-and-problems/46735/3 "2024-07-25T09:15:12Z")

</div>

Hello Christian,

This is the trigger:

 ![henk_stobbe_0-1721898712367.png](https://global.discourse-cdn.com/dynatrace/original/2X/b/b9ece1d7a3da0f14c2010e7ab5e8fc406578bdde.png)

Sending you the top/important part of the JS task:

import { execution } from ‘@dynatrace-sdk/automation-utils’;import { queryExecutionClient } from ‘@dynatrace-sdk/client-query’;import { eventsClient } from “@dynatrace-sdk/client-classic-environment-v2”;//Before this task already 2 tasks have been active with the same delaysetTimeout(() =\> {&nbsp; console.log(“1 minute has passed”);}, 119000);  
export default async function ({ execution\_id }) {&nbsp; &nbsp; try {&nbsp; &nbsp; &nbsp; &nbsp; // Get the current execution&nbsp; &nbsp; &nbsp; &nbsp; const ex = await execution(execution\_id);  
&nbsp; &nbsp; &nbsp; &nbsp; // Extract event data&nbsp; &nbsp; &nbsp; &nbsp; const data = ex.event();&nbsp; &nbsp; &nbsp; &nbsp; const url = “https :// [events.pagerduty.com/v2/enqueue](http://events.pagerduty.com/v2/enqueue)”;  
&nbsp; &nbsp; &nbsp; &nbsp; // Initialize payload and custom\_details if not present&nbsp; &nbsp; &nbsp; &nbsp; data.payload = data.payload || {};&nbsp; &nbsp; &nbsp; &nbsp; data.payload.custom\_details = data.payload.custom\_details || {};  
&nbsp; &nbsp; &nbsp; &nbsp; const eventIds = data[‘dt.davis.event\_ids’];&nbsp; &nbsp; &nbsp; &nbsp; let allTags = {};  
&nbsp; &nbsp; &nbsp; &nbsp; // Fetch event details and add them directly to custom\_details&nbsp; &nbsp; &nbsp; &nbsp; try {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (const eventId of eventIds) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const eventQuery = `fetch dt.davis.events | &nbsp;filter event.id == “${eventId}”`;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [//console.log](https://console.log)(“\*\*\*\*\*\*\*\*\*\*”,eventQuery);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const eventResponse = await queryExecutionClient.queryExecute({&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; body: {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; query: eventQuery,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; requestTimeoutMilliseconds: 60000,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fetchTimeoutSeconds: 60000&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });Retrieving the events will fail if if you do not wait for min 5 minutes.(can share full script but than I need to sanitize first (-;)KR Henk

---

<div class="post-metadata">

**Author:** ![christian\_kreuz](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/christian_kreuz/32/21669_2.png) [@christian\_kreuz](https://community.dynatrace.com/u/christian_kreuz)\
**Post date:** [July 25, 2024, 10:41am UTC](https://community.dynatrace.com/t/data-freshness-for-events-and-problems/46735/4 "2024-07-25T10:41:00Z")

</div>

A wait time of 10 seconds (let’s make it 15 seconds to be on the safe side) should be enough. In your code example, I believe you’re missing the await statement.

```javascript
export default async function ({ execution_id }) {
  console.log('Starting to sleep');
  const milliseconds = 15000; // sleep time
  await new Promise(resolve => setTimeout(resolve, milliseconds));
  console.log('Done sleeping');
}

```

Can you verify that the execution of the step that should sleep takes the expected amount of time, e.g., 15 seconds as in my example?

 ![christian_kreuz_0-1721904034611.png](https://global.discourse-cdn.com/dynatrace/original/3X/5/4/54ae2a58ed8c67cc4e13a83ed80f4f694ac7f005.png)

---

<div class="post-metadata">

**Author:** ![henk\_stobbe](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/henk_stobbe/32/30434_2.png) [@henk\_stobbe](https://community.dynatrace.com/u/henk_stobbe)\
**Post date:** [July 25, 2024, 1:45pm UTC](https://community.dynatrace.com/t/data-freshness-for-events-and-problems/46735/5 "2024-07-25T13:45:54Z")

</div>

Hello Christian,

This will make your day, I have now a 20s wait,

![henk_stobbe_0-1721915098461.png](https://global.discourse-cdn.com/dynatrace/optimized/2X/8/846c2e15280541f2a041e4121e1f6be62d470e46_2_690x36.png)

No problems!

Thanks for you help and guidance!

KR Henk
