Open Hiexy opened 6 days ago
Thanks for posting the idea!
As we write more modules, we'll see if we see this pattern over and over again, and if so, it might be worth implementing something like this!
Some technical underpinnings: We may wish to implement this as a combination of watchfiles
(to watch the input file) and donecmd
(to touch the mtime file which we could hide in the res $vardir) and ifcmd
which we have an mtime
check done automatically with golang stat
.
Note watchfiles
is described in https://github.com/purpleidea/mgmt/issues/771
If we could come up with an elegant API, we may similarly want to implement an mtimeif
so that we can compare mtimes without using bash.
On bikeshedding: I don't love the name trigger_watch
, if we get there, we should consider what to do instead. Maybe trigger_file
? Or mtime_file
or ???
(And lastly, all the autoedges magic could be done here too!)
In the exec resource, we sometimes resort to creating a trigger to know to run some commands if a file has been modified. A trigger file is created to compare the modified time of the file and the trigger file that has been created, and then the command is run based on that check.
For example, this exec resource is complex
Can be written like this instead
The
trigger_watch
option would take in a file that it should watch. Mgmt would create the trigger file, manage it, and mgmt would do the checks on that file and run the command if a change has been made.