# Watcher, difference between setting the time range using contex and without using context

**URL:** <https://discuss.elastic.co/t/watcher-difference-between-setting-the-time-range-using-contex-and-without-using-context/251965>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-alerting\
**Created:** [October 13, 2020, 8:18pm UTC](https://discuss.elastic.co/t/watcher-difference-between-setting-the-time-range-using-contex-and-without-using-context/251965 "2020-10-13T20:18:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ElasticLiver](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/elasticliver/32/64869_2.png) [@ElasticLiver](https://discuss.elastic.co/u/ElasticLiver)\
**Post date:** [October 13, 2020, 8:18pm UTC](https://discuss.elastic.co/t/watcher-difference-between-setting-the-time-range-using-contex-and-without-using-context/251965/1 "2020-10-13T20:18:11Z")

</div>

Hi, What is the difference in setting an alert with watcher using context , like this:

```auto
                "range": {
                  "@timestamp": {
                    "gte": "{{ctx.trigger.scheduled_time}}||-30m",
                    "lte": "{{ctx.trigger.scheduled_time}}"
                  }
                }

```

and not using context, like this:

```auto
                 "range": {
                   "@timestamp": {
                     "gte": "now-30m",
                     "lt": "now"
                   }
                 }

```

Is one option better than the other? one option has his benefits?

Thanks!

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [October 14, 2020, 7:39am UTC](https://discuss.elastic.co/t/watcher-difference-between-setting-the-time-range-using-contex-and-without-using-context/251965/2 "2020-10-14T07:39:52Z")

</div>

Hey,

so watches are not guaranteed to run at the exact same time when they are scheduled (imagine a node outage happening at that time or a garbage collection delaying the watch execution).

In that case `now` refers to the point in time when the watch is running, where as the trigger scheduled time refers to the point in time when the watch was supposed to run.

If you run a watch every few minutes this probably does not matter, but think might be different with a cron job for example.

Hope that helps!

--Alex

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 11, 2020, 7:39am UTC](https://discuss.elastic.co/t/watcher-difference-between-setting-the-time-range-using-contex-and-without-using-context/251965/3 "2020-11-11T07:39:56Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
