# EF2 extension running slightly more than 60 seconds: way to not trigger log alert?

**URL:** <https://community.dynatrace.com/t/ef2-extension-running-slightly-more-than-60-seconds-way-to-not-trigger-log-alert/48477>\
**Category:** Extensions\
**Tags:** extensions\
**Created:** [October 22, 2024, 9:05pm UTC](https://community.dynatrace.com/t/ef2-extension-running-slightly-more-than-60-seconds-way-to-not-trigger-log-alert/48477 "2024-10-22T21:05:17Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![AntonioSousa](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/antoniosousa/32/50_2.png) [@AntonioSousa](https://community.dynatrace.com/u/AntonioSousa)\
**Post date:** [October 22, 2024, 9:05pm UTC](https://community.dynatrace.com/t/ef2-extension-running-slightly-more-than-60-seconds-way-to-not-trigger-log-alert/48477/1 "2024-10-22T21:05:17Z")

</div>

I have an extension, which for a particular monitoring configuration, and once per hour, needs to run slightly more than 60 seconds. A log entry is created for each of the invocations, and looks like this:

```markup
Method=query: Callback Method=query took 64.1117 seconds to execute, which is longer than the interval of 60.0s

```

Is this something that can be configured, eventually at the monitoring configuration level?

---

<div class="post-metadata">

**Author:** ![DavidMass](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/davidmass/32/9065_2.png) [@DavidMass](https://community.dynatrace.com/u/DavidMass)\
**Post date:** [October 22, 2024, 9:21pm UTC](https://community.dynatrace.com/t/ef2-extension-running-slightly-more-than-60-seconds-way-to-not-trigger-log-alert/48477/2 "2024-10-22T21:21:15Z")

</div>

Hi [@AntonioSousa](https://community.dynatrace.com/user/17213),  
I’m guessing you are using the query method that runs once per minute and then calculating the once per hour to run via a counter or some other method?

You can switch to the setting the main method of your extension to use be called via the schedule ([\<no title\> — dt-sdk 1.0.0 documentation](https://dynatrace-extensions.github.io/dt-extensions-python-sdk/api/extension.html#dynatrace_extension.Extension.schedule)) method that takes in an interval which you can either hard code or pass in via the monitoring config.

For example, you can pull the frequency from the config and use it to give yourself more minutes before the callback error is thrown.

```auto
from datetime import timedelta
...

def initialize(self):
    frequency = self.activation_config.get("frequency", 1)
    self.schedule(callback=self.main_method, interval=timedelta(minutes=frequency), args=())

def main_method(self):
    # Do your work here

```

---

<div class="post-metadata">

**Author:** ![AntonioSousa](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/antoniosousa/32/50_2.png) [@AntonioSousa](https://community.dynatrace.com/u/AntonioSousa)\
**Post date:** [October 22, 2024, 9:58pm UTC](https://community.dynatrace.com/t/ef2-extension-running-slightly-more-than-60-seconds-way-to-not-trigger-log-alert/48477/3 "2024-10-22T21:58:10Z")

</div>

[@DavidMass](https://community.dynatrace.com/user/909),

Yes, using the strategy that was available in EF1 🙂  
Going to try it out, but have questions:

1. The query method will always be executed right?
2. If yes, can we use both main\_method and query
3. If we would like to run it every hour, is there a way to define which minute it would run?

---

<div class="post-metadata">

**Author:** ![DavidMass](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/davidmass/32/9065_2.png) [@DavidMass](https://community.dynatrace.com/u/DavidMass)\
**Post date:** [October 22, 2024, 10:10pm UTC](https://community.dynatrace.com/t/ef2-extension-running-slightly-more-than-60-seconds-way-to-not-trigger-log-alert/48477/4 "2024-10-22T22:10:31Z")

</div>

I understand 👍  
With the EF2 SDK, you don’t need to have a query method. It is now still a special method but it’s just scheduled (using a similar method to the self.schedule way) internally within the SDK at a hard coded interval (1 minute). If it’s not defined the SDK will still work.

Yes, you can have both your main\_method and a query method where query would run once a minute (automatically) and then you would need to “manually” schedule your main\_method. You can also schedule more than 1 method each with it’s own interval.

Using that set up, no, it would be scheduled to run whenever the AG receives the configuration so there is no way to guarantee it to run at a specific minute in the hour.

Off the top of my head though, you could have a delay where in the initialize method you “sleep” until the minute you want comes up and then schedule it.

---

<div class="post-metadata">

**Author:** ![MostafaHussein](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/mostafahussein/32/2785_2.png) [@MostafaHussein](https://community.dynatrace.com/u/MostafaHussein)\
**Post date:** [October 22, 2024, 11:03pm UTC](https://community.dynatrace.com/t/ef2-extension-running-slightly-more-than-60-seconds-way-to-not-trigger-log-alert/48477/5 "2024-10-22T23:03:48Z")

</div>

Hello&nbsp;[@AntonioSousa](https://community.dynatrace.com/user/17213)&nbsp;,

when checking the extension source in [github](https://github.com/dynatrace-extensions/dt-extensions-python-sdk/blob/main/dynatrace_extension/sdk/extension.py) I’ve found that there’s constants were defined in the file extension.py as the following figure

```python
HEARTBEAT_INTERVAL = timedelta(seconds=50)
METRIC_SENDING_INTERVAL = timedelta(seconds=30)
SFM_METRIC_SENDING_INTERVAL = timedelta(seconds=60)
TIME_DIFF_INTERVAL = timedelta(seconds=60)

```

 ![MostafaHussein_0-1729637694772.png](https://global.discourse-cdn.com/dynatrace/original/3X/9/a/9aa055afc0c6548ca2e4bddffeb813a6498eb391.png)

after searching for `SFM_METRIC_SENDING_INTERVAL` I’ve found that it’s used in class `Extension` as the following figure

 ![MostafaHussein_2-1729637999362.png](https://global.discourse-cdn.com/dynatrace/original/3X/8/e/8e103dffaacdc91a6f83cb448cf44a305a56fb4d.png)

so you can try simply redefine them with your own values within your own extension file \_\_main\_\_.py, I&nbsp;hope you get it works.

BR,

Mostafa Hussein.

---

<div class="post-metadata">

**Author:** ![RTOWNSEND](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/rtownsend/32/7966_2.png) [@RTOWNSEND](https://community.dynatrace.com/u/RTOWNSEND)\
**Post date:** [November 21, 2024, 10:43pm UTC](https://community.dynatrace.com/t/ef2-extension-running-slightly-more-than-60-seconds-way-to-not-trigger-log-alert/48477/6 "2024-11-21T22:43:55Z")

</div>

Hello Antonio,

I created a custom XenServer extension, and I am encountering the same error message. Error shown below,  
Method=query: Callback Method=query took 62.5491 seconds to execute, which is longer than the interval of 60.0s

Did you have successful results applying the fix David Mass recommended?

---

<div class="post-metadata">

**Author:** ![AntonioSousa](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/antoniosousa/32/50_2.png) [@AntonioSousa](https://community.dynatrace.com/u/AntonioSousa)\
**Post date:** [November 22, 2024, 9:46am UTC](https://community.dynatrace.com/t/ef2-extension-running-slightly-more-than-60-seconds-way-to-not-trigger-log-alert/48477/7 "2024-11-22T09:46:51Z")

</div>

[@RTOWNSEND](https://community.dynatrace.com/user/33216),

I have not yet done any changes from my side…

---

<div class="post-metadata">

**Author:** ![RTOWNSEND](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/rtownsend/32/7966_2.png) [@RTOWNSEND](https://community.dynatrace.com/u/RTOWNSEND)\
**Post date:** [November 25, 2024, 6:05pm UTC](https://community.dynatrace.com/t/ef2-extension-running-slightly-more-than-60-seconds-way-to-not-trigger-log-alert/48477/8 "2024-11-25T18:05:46Z")

</div>

Hi [@DavidMass](https://community.dynatrace.com/user/909)&nbsp;,

I applied the recommended code shown below and I am still receiving the same error Antonio reported. When manually running \_\_,main.py\_\_ , I can see the frequency set to 20min( Please reference the second output shown below).&nbsp; Any guidance you can provide would be greatly appreciated.

Thank You!

Error MessageMethod=query: Callback Method=query took 85.6351 seconds to execute, which is longer than the interval of 60.0sCodedef initialize(self):&nbsp; &nbsp; &nbsp; &nbsp; self.extension\_name = ‘xensrvapi’&nbsp; &nbsp; &nbsp; &nbsp; self.logger.info(f"{self.extension\_name} initialized.“)&nbsp; &nbsp; &nbsp; &nbsp; frequency = int(self.activation\_config.get(“frequency”, 20))&nbsp; &nbsp; &nbsp; &nbsp; interval = timedelta(seconds=1200)&nbsp; &nbsp; &nbsp; &nbsp; self.schedule(callback=self.query, interval=interval)&nbsp; &nbsp; &nbsp; &nbsp; self.logger.info(f"scheduling query with an interval of {interval} (frequency: {frequency} minutes.”)Output from manual execution via VsCode2024-11-25 11:53:06,966 [INFO] api (ThreadPoolExecutor-1\_0): send\_status: ‘{“status”: “OK”, “message”: “”}’  
2024-11-25 11:53:06,968 [INFO] xensrvapi (MainThread): xensrvapi initialized.  
2024-11-25 11:53:06,968 [INFO] xensrvapi (MainThread): scheduling query with an interval of 0:20:00 (frequency: 20 minutes.  
2024-11-25 11:53:06,968 [INFO] api (MainThread): -----------------------------------------------------  
2024-11-25 11:53:06,969 [INFO] api (MainThread): Starting ExtensionImpl(name=xensrvapi, version=0.0.1)  
2024-11-25 11:53:06,969 [INFO] api (MainThread): -----------------------------------------------------  
2024-11-25 11:53:06,969 [INFO] api (ThreadPoolExecutor-1\_0): send\_sfm\_metric: dsfm:datasource.python.threads,dt.extension.config.id=“development\_config\_id” count,delta=3  
2024-11-25 11:53:06,970 [INFO] xensrvapi (ThreadPoolExecutor-0\_0): Query method started for xensrvapi.

---

<div class="post-metadata">

**Author:** ![david\_lopes](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/david_lopes/32/27273_2.png) [@david\_lopes](https://community.dynatrace.com/u/david_lopes)\
**Post date:** [November 27, 2024, 6:46pm UTC](https://community.dynatrace.com/t/ef2-extension-running-slightly-more-than-60-seconds-way-to-not-trigger-log-alert/48477/9 "2024-11-27T18:46:04Z")

</div>

Please do NOT do this, these are internal values of the periods in which we communicate to the EEC, it has nothing to do with the original issue.

To fix the original issue just schedule methods to run for more than 60 seconds, do NOT attempt to schedule the query method itself, as that one is a special method that is always scheduled to run every 60 seconds.
