Commit | Line | Data |
---|---|---|
e879cdc3 SBS |
1 | * bklog task list |
2 | ** TODO Adjust filename duration dynamically | |
3 | 2020-07-12T21:17Z; bktei> Currently, the "duration" component of the | |
4 | output filename for a given chunk is calculated from the ~bufferTTL~ | |
5 | variable which does not necessarily reflect the amount of buffer lines | |
6 | being read into a given chunk, especially since lines of stdin may be | |
7 | received while synchronous processing occurs before a new | |
8 | ~magicProcessWriteBuffer &~ job is spun off. | |
9 | ||
10 | A better way to specify the duration is to maintain a pair of | |
11 | timestamp varriables before each ~magicProcessWriteBuffer~ command is | |
12 | run. Within the asynchronous write job the time difference between the | |
13 | two time stamps may be evaluated in order to determine how much time | |
14 | has passed since the last write operation started. The last line read | |
15 | into the buffer when the ~while read~ loop finishes should be the most | |
16 | current value and so one of the two timestamps should be recorded | |
17 | then. The other time stamp should simply be the previous loop's | |
18 | timestamp value. | |
19 | ||
20 | For example: | |
21 | ||
22 | #+BEGIN_EXAMPLE | |
23 | # MAIN LOOP: Run until script TTL seconds pass | |
24 | bufferRound=0; | |
25 | while [[ $SECONDS -lt "scriptTTL" ]]; do | |
26 | vbm "STATUS:$fn:Starting buffer round:$bufferRound"; | |
27 | bufferTOD="$((SECONDS + bufferTTL))"; # Set buffer round time-of-death | |
28 | # Consume stdin to fill buffer until buffer time-of-death (TOD) arrives | |
29 | while read -r -t "$bufferTTL" line && [[ $SECONDS -lt "$bufferTOD" ]]; do | |
30 | # Append line to buffer array | |
31 | buffer+=("$line"); | |
32 | done; | |
33 | #====BEGIN NEW CODE HERE==== | |
34 | bufferTimestampOld="$bufferTimestampNew"; | |
35 | bufferTimeStampNew="$(date --iso-8601=seconds)"; | |
36 | #====END NEW CODE HERE==== | |
37 | # Create dir_tmp if missing | |
38 | if ! [[ -d "$dir_tmp" ]]; then | |
39 | yell "ERROR:$fn:dir_tmp existence failure:$dir_tmp"; | |
40 | try mkdir "$dir_tmp" && vbm "DEBUG :$fn:Working dir recreated dir_tmp:$dir_tmp"; fi | |
41 | # Update cmd_encrypt, cmd_encrypt_suffix | |
42 | magicParseRecipients; | |
43 | # Export buffer to asynchronous processing. | |
44 | magicProcessWriteBuffer & | |
45 | unset buffer; # Clear buffer array for next bufferRound | |
46 | # Increment buffer round | |
47 | ((bufferRound++)); | |
48 | done; | |
49 | #+END_EXAMPLE | |
50 | ||
51 | Then, within the ~magicProcessWriteBuffer()~ function, the difference | |
52 | in seconds between ~bufferTimestampOld~ and ~bufferTimestampNew~ may | |
53 | be calculated and an appropriate duration string generated from the | |
54 | ~timeDuration()~ function. | |
55 | ||
56 | ||
57 | * bklog narrative | |
58 |