Final block in Actions
Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
Since action runs once per file, it's challenging to have something trigger at the end of the run. I'm frustrated because, although I can echo something into a log file, it happens once per file.
Describe the solution you'd like A clear and concise description of what you want to happen.
I want to see something like
rules:
- name: "Move Documents to Documents directory"
locations:
- ~/Downloads
filters:
- name
- extension:
- txt
- pdf
actions:
- move: ~/Documents
- shell: 'echo "Moved {name} to Documents" >> ~/move_log.txt'
- final:
- shell: 'echo "All files moved at {time} >> ~/move_log.txt"
Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.
I haven't, as I didn't see anything in the documentation that suggests this can be changed.
Additional context Add any other context or screenshots about the feature request here.
To help increase the precision @Programazing, are you suggesting an action-like facility that'd execute once at the end of each rule, after all files have been processed by that rules (and not once after all files for all rules have been processed)?
@zor-el correct
@Programazing, and is echoing/logging a completion message your use case, or do you hope to address something else with an end-of-rule action?
@zor-el Now that I think about it, what I REALLY wanted was the ability to write to a specific error log file, and was using the idea of a final action to do that.
I have a log scanning app that sends me an email when specific log files appear.
I envision that when there's an error or a failure, it creates a log file in a user-defined location.
I phrased it as a final action because I thought it would be generic and valuable enough to achieve that, and whatever else the community might want.
@tfeldmann it seems to me a logging capability with a log level CLI option is already half in place. There is already an option to control the output verbosity (--format). Since output can be redirected with >, it seems "the only" thing missing would be a "rule processing summary" output. AFAICT this would be synergistic with other feature requests. (Ex. the one about a --silent option - #425.)
BTW, apologies for stepping in out of the blue. As a long time user I have a vested interest in the leanness of this tool. I might be wrong, but - as charming as an end-of-rule action type appears - my hunch is it might be harder and take longer to implement consistently (without interfering with possible future rule optimizations) than a logging or output format facility.
@Programazing, the appearance of a log file implies there is a new log file for every new program run with errors. Typically log files are longer lived than a single run though. (Messages are typically appended to an existing log file.) Would a time stamp change / modification of a log file also work for you?
(Just gathering information to help make a sane decision. :))
Yes.
I store logs in temp/AppName and only append on failure.
That way, a script running in cron sees the file, and the workflow is:
If a file exists here, something went wrong, email the contents to the user and delete the file.
Though I doubt others do that.
You can do action-only rules like this:
rules:
- actions:
- echo: "Hello"
- shell: "some command"
But it seems this is not really your usecase? Have you looked into --format=errorsonly?