Check Image Save

Report generated on May-27 10:00 pm

Pier last restarted: Fri May 24 02:20:01 UTC 2024

A-OK - Image file is newer (2024-05-27T18:06:03+00:00)


(PRScheduledTaskExamples newForKernelNamed: 'Pier') reportOfFile: 'STARTED_PHARO.txt' onPageAt: '/Blog/Social Tasks/Democracy Action/Check Image Save/Report' modifyUsing: [ :restartString || imageFile transactionFile prefix lastRestart lastLine | prefix := ''. lastRestart := DateAndTime epoch. (restartString isEmpty not and: [ (lastLine := restartString lines last) size > 74 ]) ifTrue: [ prefix := 'Pier last restarted: ', (lastLine copyFrom: 47 to: 74), String crlfcrlf. lastRestart := [ | date time | date := ((lastLine copyFrom: 51 to: 57), (lastLine copyFrom: 71 to: 74)) asDate. time := (lastLine copyFrom: 58 to: 65) asTime. DateAndTime date: date time: time ] on: Error do: [ DateAndTime epoch ] ]. (imageFile := FileLocator workingDirectory / 'pier_addons.image') exists ifFalse: [ 'Image file does not exist!' ] ifTrue: [ (transactionFile := FileLocator workingDirectory / 'transactions.txt') exists ifFalse: [ 'Transaction file does not exist!' ] ifTrue: [ ((FileSystem disk modificationTimeOf: transactionFile) between: (FileSystem disk modificationTimeOf: imageFile) and: lastRestart) ifTrue: [ prefix, 'NOT OK - Pier was restarted after changes but before image save' ] ifFalse: [ PRKernel instances size = 1 ifFalse: [ 'Code is not prepared for more than 1 kernel' ] ifTrue: [ (FileSystem disk modificationTimeOf: imageFile) > (FileSystem disk modificationTimeOf: transactionFile) ifTrue: [ prefix, 'A-OK - Image file is newer (' , (FileSystem disk modificationTimeOf: imageFile) asString , ')' ] ifFalse: [ PRKernel instances anyOne persistency duration > (DateAndTime now - (FileSystem disk modificationTimeOf: transactionFile)) ifTrue: [ prefix, 'Could be OK - There are unsaved edits, but transactions is not older than persistency duration' ] ifFalse: [ prefix, 'NOT OK - There are edits that may be lost!' ] ] ] ] ] ] ].

Explanation:

  • Add a prefix for the last time check_pier.sh restarted pier - This is heavily dependent on the format of this scripts output
  • Sanity checks:
    • Image file must exist
    • transactions.txt should exist if anything has been edited
    • There must be only 1 kernel
  • If pier was restarted after changes were made but before the image was saved, there are problems (if there are issues with checking the time of the restart, this won't work)
  • If the image file is newer than transaction.txt, there is no concern
  • otherwise:
    • Time difference between transactions.txt and the image is less than the persistency duration, then edits should be saved soon
    • Otherwise
      • If the time between now and the last edit is less than the persistency duration, then the edits should be saved soon
      • When there are edits older than the persistency and the image has not been saved since then then edits have been lost!

Other discoveries:

  • For Fedora - Smalltalk imageFile is the memory file, it is constantly being updated - use the file name instead - Check with:
    FileSystem disk modificationTimeOf: Smalltalk imageFile