Comparing current value to weekly minimum value


While my problem seems very trivial to solve, I still struggle coming up with a solution.

I have a stream of data at a db called “products” with “autogen” retention policy (it has 2d lifespan and is gathering data every 10s).
I also have a downsampled data inside the same “products” db with “rp_1h_window” retention policy.

The field I’m interested in is called “price”.

I want to write a TICK script that will notify me whenever “products”.“autogen” gets a new “price” with a value lower than minimal “price” of the previous week in “products”.“rp_1h_window”.

I suppose I should use a batch script for that?

I tried the following, but it does not work for some reason:

dbrp "products"."autogen"
dbrp "products"."rp_1h_window"

var minPriceLast7d = batch
        SELECT min("price")
        FROM "products"."rp_1h_window"."my_metric_name"

var minPriceLastMinute = batch
        SELECT min("price")
        FROM "products"."autogen"."my_metric_name"

var data = minPriceLast7d
    .as('minPriceLast7d', 'minPriceLastMinute')
    .crit(lambda: "minPriceLastMinute.min" < "minPriceLast7d.min")
    .message('The price is lower!')

The names are correct. The .telegram() is working fine, I’ve tested it separately.

here’s the script’s graph:

graph [throughput="0.00 batches/s"];

query3 [avg_exec_time_ns="687.020305ms" batches_queried="15" errors="0" points_queried="15" working_cardinality="0" ];
query3 -> log4 [processed="15"];

log4 [avg_exec_time_ns="4.164149ms" errors="0" working_cardinality="0" ];
log4 -> join6 [processed="15"];

query1 [avg_exec_time_ns="498.765513ms" batches_queried="15" errors="0" points_queried="15" working_cardinality="0" ];
query1 -> log2 [processed="15"];

log2 [avg_exec_time_ns="1.888199ms" errors="0" working_cardinality="0" ];
log2 -> join6 [processed="15"];

join6 [avg_exec_time_ns="965.726µs" errors="0" working_cardinality="1" ];
join6 -> log7 [processed="28"];

log7 [avg_exec_time_ns="44.945µs" errors="0" working_cardinality="0" ];
log7 -> alert8 [processed="28"];

alert8 [alerts_inhibited="0" alerts_triggered="0" avg_exec_time_ns="3.280364ms" crits_triggered="0" errors="0" infos_triggered="0" oks_triggered="0" warns_triggered="0" working_cardinality="1" ]

What I may be doing wrong and how should I write the script?