fix(bklog):Fix buffer drift via SECONDS
[EVA-2020-02.git] / exec / bklog-plan.org
... / ...
CommitLineData
1* bklog task list
2** TODO Adjust filename duration dynamically
32020-07-12T21:17Z; bktei> Currently, the "duration" component of the
4output filename for a given chunk is calculated from the ~bufferTTL~
5variable which does not necessarily reflect the amount of buffer lines
6being read into a given chunk, especially since lines of stdin may be
7received while synchronous processing occurs before a new
8~magicProcessWriteBuffer &~ job is spun off.
9
10A better way to specify the duration is to maintain a pair of
11timestamp varriables before each ~magicProcessWriteBuffer~ command is
12run. Within the asynchronous write job the time difference between the
13two time stamps may be evaluated in order to determine how much time
14has passed since the last write operation started. The last line read
15into the buffer when the ~while read~ loop finishes should be the most
16current value and so one of the two timestamps should be recorded
17then. The other time stamp should simply be the previous loop's
18timestamp value.
19
20For 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
51Then, within the ~magicProcessWriteBuffer()~ function, the difference
52in seconds between ~bufferTimestampOld~ and ~bufferTimestampNew~ may
53be calculated and an appropriate duration string generated from the
54~timeDuration()~ function.
55
56
57* bklog narrative
58