@@ -2,11 +2,12 @@ use std::fs;
2
2
mod bash_plugin;
3
3
mod python_plugin;
4
4
use bash_plugin:: load as load_sh_plugin;
5
+ use chrono:: { DateTime , Utc } ;
5
6
use python_plugin:: load as load_py_plugin;
6
7
7
8
use crate :: intervals:: { time_till_next_run, wait_duration} ;
8
9
use crate :: stdout_styling:: style_line;
9
- use paws_config:: { KittypawsConfig , PluginConfig } ;
10
+ use paws_config:: { KittypawsConfig , PluginConfig , Duration as ConfigDuration } ;
10
11
use std:: collections:: HashMap ;
11
12
use std:: path:: PathBuf ;
12
13
use std:: thread;
@@ -52,8 +53,17 @@ fn call_plugin(name: &str, plugin: &CallablePlugin, config: &HashMap<String, Str
52
53
}
53
54
}
54
55
55
- fn start_plugin_loop ( plugin : CallablePlugin , config : PluginConfig ) -> JoinHandle < ( ) > {
56
+ fn start_plugin_loop (
57
+ plugin : CallablePlugin ,
58
+ config : PluginConfig ,
59
+ loop_duration : & Option < ConfigDuration > ,
60
+ ) -> JoinHandle < ( ) > {
56
61
let startup = config. startup . into ( ) ;
62
+ let mut deadline: Option < DateTime < Utc > > = None ;
63
+
64
+ if let Some ( loop_duration) = loop_duration {
65
+ deadline = Some ( Utc :: now ( ) + loop_duration. as_chrono ( ) ) ;
66
+ }
57
67
58
68
thread:: spawn ( move || {
59
69
match startup {
@@ -73,6 +83,11 @@ fn start_plugin_loop(plugin: CallablePlugin, config: PluginConfig) -> JoinHandle
73
83
if time_till_next_run ( & config. frequency ) . is_none ( ) {
74
84
break ;
75
85
}
86
+ if let Some ( deadline) = deadline {
87
+ if Utc :: now ( ) > deadline {
88
+ break ;
89
+ }
90
+ }
76
91
}
77
92
} )
78
93
}
@@ -83,7 +98,7 @@ pub fn start_main_loop(config: KittypawsConfig) {
83
98
for plugconf in config. plugins {
84
99
match load_plugin ( & plugconf. name ) {
85
100
Ok ( plugin) => {
86
- let thread = start_plugin_loop ( plugin, plugconf) ;
101
+ let thread = start_plugin_loop ( plugin, plugconf, & config . duration ) ;
87
102
88
103
handles. push ( thread) ;
89
104
}
0 commit comments