Skip to content

Commit

Permalink
implement worker logger [feenkcom/gtoolkit#3778]
Browse files Browse the repository at this point in the history
- add `TAsyncFutureLogger`
- add `AsyncFutureDetailedTranscriptLogger`
- add `AsyncFutureTranscriptLogger`
  • Loading branch information
JurajKubelka committed May 15, 2024
1 parent 37aa3b6 commit 23a47d3
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 4 deletions.
59 changes: 59 additions & 0 deletions src/Futures/AsyncFutureDetailedTranscriptLogger.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
Class {
#name : #AsyncFutureDetailedTranscriptLogger,
#superclass : #Object,
#traits : 'TAsyncFutureLogger',
#classTraits : 'TAsyncFutureLogger classTrait',
#instVars : [
'transcript'
],
#category : #'Futures-Executor - Logger'
}

{ #category : #accessing }
AsyncFutureDetailedTranscriptLogger >> initialize [
super initialize.
transcript := NonInteractiveTranscript stdout
]

{ #category : #private }
AsyncFutureDetailedTranscriptLogger >> pendingItem: aPendingTask indent: anIndent [
| aDescription |
anIndent
timesRepeat: [ transcript
space;
space ].
aDescription := [ aPendingTask gtCompositionDescription asString ]
on: Error
do: [ :anError | anError return: aPendingTask className , ' ' , anError printString ].
aDescription lines
do: [ :eachLine |
transcript
nextPutAll: eachLine trimBoth;
space ].
transcript newLine
]

{ #category : #private }
AsyncFutureDetailedTranscriptLogger >> pendingItems: someAsyncObjects indent: anIndent [
someAsyncObjects
do: [ :eachAsyncObject |
self pendingItem: eachAsyncObject indent: anIndent.
self
pendingItems: eachAsyncObject gtCompositionChildren
indent: anIndent + 1 ]
]

{ #category : #logging }
AsyncFutureDetailedTranscriptLogger >> pendingTask: aPendingTask [
self pendingItems: {aPendingTask} indent: 0
]

{ #category : #accessing }
AsyncFutureDetailedTranscriptLogger >> transcript [
^ transcript ifNil: [ transcript := NonInteractiveTranscript stdout ]
]

{ #category : #accessing }
AsyncFutureDetailedTranscriptLogger >> transcript: anObject [
transcript := anObject
]
33 changes: 29 additions & 4 deletions src/Futures/AsyncFutureThreadPoolWorker.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,27 @@ Class {
'group',
'currentTaskProcess',
'workerProcess',
'futuresCounter'
'futuresCounter',
'logger'
],
#classVars : [
'DefaultLogger'
],
#category : #'Futures-Executor - Thread Pool'
}

{ #category : #accessing }
AsyncFutureThreadPoolWorker class >> defaultLogger [
<return: #TAsyncFutureLogger>
^ DefaultLogger ifNil: [
DefaultLogger := AsyncFutureDetailedTranscriptLogger new ]
]

{ #category : #accessing }
AsyncFutureThreadPoolWorker class >> defaultLogger: aLogger [
DefaultLogger := aLogger
]

{ #category : #'api - accessing' }
AsyncFutureThreadPoolWorker >> acceptsFutures [
<return: #Boolean>
Expand Down Expand Up @@ -111,6 +127,17 @@ AsyncFutureThreadPoolWorker >> isWaitingOnSemaphore [
ifNotNil: [ :aProcess | aProcess suspendingList notNil ] ]
]

{ #category : #accessing }
AsyncFutureThreadPoolWorker >> logger [
<return: #TAsyncFutureLogger>
^ logger ifNil: [ self class defaultLogger ]
]

{ #category : #accessing }
AsyncFutureThreadPoolWorker >> logger: aLogger [
logger := aLogger
]

{ #category : #'api - lifecycle' }
AsyncFutureThreadPoolWorker >> maintanance [
]
Expand Down Expand Up @@ -167,9 +194,7 @@ AsyncFutureThreadPoolWorker >> privateExecuteFuture: anAsyncPendingFuturePromise
| isPending |
isPending := aSemaphore waitTimeoutSeconds: 60.
isPending ifTrue: [
NonInteractiveTranscript stdout
nextPutAll: aPendingTask printString;
cr ].
self logger pendingTask: aPendingTask ].
"if the process is terminated, then there is no reason to wait for it even if the semaphore was not signalled "
isPending := isPending
and: [ currentTaskProcess isTerminated not ].
Expand Down
33 changes: 33 additions & 0 deletions src/Futures/AsyncFutureTranscriptLogger.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Class {
#name : #AsyncFutureTranscriptLogger,
#superclass : #Object,
#traits : 'TAsyncFutureLogger',
#classTraits : 'TAsyncFutureLogger classTrait',
#instVars : [
'transcript'
],
#category : #'Futures-Executor - Logger'
}

{ #category : #accessing }
AsyncFutureTranscriptLogger >> initialize [
super initialize.
transcript := NonInteractiveTranscript stdout
]

{ #category : #logging }
AsyncFutureTranscriptLogger >> pendingTask: aPendingTask [
transcript
nextPutAll: aPendingTask printString;
cr
]

{ #category : #accessing }
AsyncFutureTranscriptLogger >> transcript [
^ transcript ifNil: [ transcript := NonInteractiveTranscript stdout ]
]

{ #category : #accessing }
AsyncFutureTranscriptLogger >> transcript: anObject [
transcript := anObject
]
9 changes: 9 additions & 0 deletions src/Futures/TAsyncFutureLogger.trait.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Trait {
#name : #TAsyncFutureLogger,
#category : #'Futures-Executor - Logger'
}

{ #category : #logging }
TAsyncFutureLogger >> pendingTask: aPendingTask [

]

0 comments on commit 23a47d3

Please sign in to comment.