@@ -1014,7 +1014,7 @@ async fn handle_derived_stream_triggers(
1014
1014
chrono:: Duration :: try_minutes ( delay_in_mins as _ ) . and_then ( |td| td. num_microseconds ( ) )
1015
1015
} )
1016
1016
. unwrap_or_default ( ) ;
1017
- let mut supposed_to_be_run_at = trigger. next_run_at - user_defined_delay;
1017
+ let supposed_to_be_run_at = trigger. next_run_at - user_defined_delay;
1018
1018
let period_num_microseconds = Duration :: try_minutes ( derived_stream. trigger_condition . period )
1019
1019
. unwrap ( )
1020
1020
. num_microseconds ( )
@@ -1023,24 +1023,6 @@ async fn handle_derived_stream_triggers(
1023
1023
let ( mut start, mut end) = if derived_stream. start_at . is_some ( ) && trigger. data . is_empty ( ) {
1024
1024
( derived_stream. start_at , supposed_to_be_run_at)
1025
1025
} else if let Some ( t0) = start_time {
1026
- // Don't use only the period_num_microseconds, because, then the delay is lets say 10 secs
1027
- // The following code will make a separate query to cover the delay period of 10 secs which
1028
- // is unnecessary. Hence, we need to check how big the delay is.
1029
- // Note: For pipeline, period and frequency both have the same value.
1030
-
1031
- // For derived stream, period is in minutes, so we need to convert it to seconds for
1032
- // align_time
1033
- if derived_stream. trigger_condition . align_time {
1034
- let aligned_curr_time = TriggerCondition :: align_time (
1035
- supposed_to_be_run_at,
1036
- derived_stream. tz_offset ,
1037
- derived_stream. trigger_condition . period * 60 ,
1038
- ) ;
1039
- // conditionally modify supposed_to_be_run_at
1040
- if aligned_curr_time > t0 {
1041
- supposed_to_be_run_at = aligned_curr_time;
1042
- }
1043
- }
1044
1026
// If the delay is equal to or greater than the frequency, we need to ingest data one by
1045
1027
// one If the delay is less than the frequency, we need to ingest data for
1046
1028
// the "next run at" period, For example, if the current time is 5:19pm,
@@ -1057,6 +1039,18 @@ async fn handle_derived_stream_triggers(
1057
1039
} else {
1058
1040
( None , supposed_to_be_run_at)
1059
1041
} ;
1042
+ // For derived stream, period is in minutes, so we need to convert it to seconds for align_time
1043
+ if derived_stream. trigger_condition . align_time {
1044
+ let aligned_curr_time = TriggerCondition :: align_time (
1045
+ end,
1046
+ derived_stream. tz_offset ,
1047
+ derived_stream. trigger_condition . period * 60 ,
1048
+ ) ;
1049
+ // conditionally modify supposed_to_be_run_at
1050
+ if start. is_none_or ( |t0| t0 < aligned_curr_time) {
1051
+ end = aligned_curr_time;
1052
+ }
1053
+ }
1060
1054
1061
1055
// In case the scheduler background job (watch_timeout) updates the trigger retries
1062
1056
// (not through this handler), we need to skip to the next run at but with the same
@@ -1069,12 +1063,14 @@ async fn handle_derived_stream_triggers(
1069
1063
new_trigger. module_key
1070
1064
) ;
1071
1065
// Go to the next nun at, but use the same trigger start time
1072
- new_trigger. next_run_at = derived_stream. trigger_condition . get_next_trigger_time (
1073
- false ,
1074
- derived_stream. tz_offset ,
1075
- false ,
1076
- Some ( end + user_defined_delay) ,
1077
- ) ?;
1066
+ new_trigger. next_run_at = derived_stream
1067
+ . trigger_condition
1068
+ . get_next_trigger_time_non_aligned (
1069
+ false ,
1070
+ derived_stream. tz_offset ,
1071
+ false ,
1072
+ Some ( trigger. next_run_at ) ,
1073
+ ) ?;
1078
1074
// Start over next time
1079
1075
new_trigger. retries = 0 ;
1080
1076
db:: scheduler:: update_trigger ( new_trigger) . await ?;
@@ -1298,11 +1294,6 @@ async fn handle_derived_stream_triggers(
1298
1294
} else {
1299
1295
// SUCCESS: move the time range forward by frequency and continue
1300
1296
start = Some ( trigger_results. end_time ) ;
1301
- // There could still be some data to be processed for the current period
1302
- // so we need to move the end time forward by the period length or the
1303
- // remaining time whichever is smaller
1304
- let _end = period_num_microseconds + 1 ;
1305
- end += _end;
1306
1297
trigger_data_stream. query_took = trigger_results. query_took ;
1307
1298
}
1308
1299
} else {
@@ -1316,11 +1307,6 @@ async fn handle_derived_stream_triggers(
1316
1307
1317
1308
// move the time range forward by frequency and continue
1318
1309
start = Some ( trigger_results. end_time ) ;
1319
- // There could still be some data to be processed for the current period
1320
- // so we need to move the end time forward by the period length or the remaining
1321
- // time whichever is smaller
1322
- let _end = period_num_microseconds + 1 ;
1323
- end += _end;
1324
1310
}
1325
1311
}
1326
1312
} ;
@@ -1345,12 +1331,14 @@ async fn handle_derived_stream_triggers(
1345
1331
&& new_trigger. retries < max_retries)
1346
1332
{
1347
1333
// Go to the next nun at, but use the same trigger start time
1348
- new_trigger. next_run_at = derived_stream. trigger_condition . get_next_trigger_time (
1349
- false ,
1350
- derived_stream. tz_offset ,
1351
- false ,
1352
- Some ( end + user_defined_delay) ,
1353
- ) ?;
1334
+ new_trigger. next_run_at = derived_stream
1335
+ . trigger_condition
1336
+ . get_next_trigger_time_non_aligned (
1337
+ false ,
1338
+ derived_stream. tz_offset ,
1339
+ false ,
1340
+ Some ( trigger. next_run_at ) ,
1341
+ ) ?;
1354
1342
1355
1343
// If the trigger didn't fail, we need to reset the `retries` count.
1356
1344
// Only cumulative failures should be used to check with `max_retries`
0 commit comments