Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chapter03 Logging issue #5

Open
Castro-711 opened this issue Oct 16, 2023 · 1 comment
Open

Chapter03 Logging issue #5

Castro-711 opened this issue Oct 16, 2023 · 1 comment

Comments

@Castro-711
Copy link

Castro-711 commented Oct 16, 2023

I seem to be having trouble getting the unhappy path to log an error for the simplequestion exercise in Chapter03.

In an effort to help it timeout & see similar logging to the unhappy path shared in the book

[Worker $] - worker-text-a: DONE!
[Manager$] - text-a read by worker-text-a
[Worker $] - worker-text-b: DONE!
[Manager$] - text-b read by worker-text-b
[Manager$] - parsing text-c' has failed with [Ask timed out on 
[Actor[akka://example-ask-without-content/user/manager-1/
worker-text-c#-1664156553]] after [3000 ms]. Message of type 
[ask.simple.Worker$Parse]. A typical reason for 
`AskTimeoutException` is that the recipient actor 
didn't send a reply.
[Worker $] - worker-text-c: DONE!
[DeadLetterActorRef] - Message [ask.simple.Worker$Done$] 
to Actor[akka://example-ask-without-content/deadLetters] 
was not delivered. [1] dead letters encountered. If this is 
not an expected behavior then 
Actor[akka://example-ask-without-content/deadLetters] may have
terminated unexpectedly. This logging can be turned off or 
adjusted with configuration settings 'akka.log-dead-letters' 
and 'akka.log-dead-letters-during-shutdown'.

I reduced the Timeout within the Manager.setup & added some logging. I also reduced the random range for the Random.between & printed out from within fakeLengthyParse to try better understand why it is not working. I tried to create a branch to share but don't have access, here is the patch

diff --git a/chapter03/src/main/scala/simplequestion/Manager.scala b/chapter03/src/main/scala/simplequestion/Manager.scala
index 97ecb35..8659ed3 100644
--- a/chapter03/src/main/scala/simplequestion/Manager.scala
+++ b/chapter03/src/main/scala/simplequestion/Manager.scala
@@ -17,7 +17,9 @@ object Manager {
 
   def apply(): Behavior[Command] =
     Behaviors.setup { context =>
-      implicit val timeout: Timeout = Timeout(3, SECONDS)
+      implicit val timeout: Timeout = Timeout(1, SECONDS)
+      context.log.info(
+        s"Logging info from Manager with timeout: $timeout")
 
       Behaviors.receiveMessage { message =>
         message match {
diff --git a/chapter03/src/main/scala/simplequestion/Worker.scala b/chapter03/src/main/scala/simplequestion/Worker.scala
index 87e967e..3c3c056 100644
--- a/chapter03/src/main/scala/simplequestion/Worker.scala
+++ b/chapter03/src/main/scala/simplequestion/Worker.scala
@@ -27,8 +27,10 @@ object Worker {
     }
 
   private def fakeLengthyParsing(text: String): Unit = {
-    val endTime =
-      System.currentTimeMillis + Random.between(2000, 4000)
+    val random = Random.between(1000, 1500) // will always exceed 1 SECOND timeout
+    val endTime = System.currentTimeMillis + random
+    println(
+      s"Logging the random value ($random) & the associated text ($text)")
     while (endTime > System.currentTimeMillis) {}
   }
 }

Here is some sample logs after my changes

[info] running simplequestion.SimpleQuestionApp 
press ENTER to terminate
2023-10-17 10:19:35,450 INFO  [Manager$] - Logging info from Manager with timeout: Timeout(1 second)
Logging the random value (1488) & the associated text (text-a)
Logging the random value (1265) & the associated text (text-b)
Logging the random value (1234) & the associated text (text-c)
2023-10-17 10:19:35,452 INFO  [CoordinatedShutdown] - Running CoordinatedShutdown with reason [ActorSystemTerminateReason]
[success] Total time: 2 s, completed 17 Oct 2023, 10:19:35
[IJ]2023-10-17 10:19:36,686 INFO  [Worker$] - worker-text-c: done
2023-10-17 10:19:36,717 INFO  [Worker$] - worker-text-b: done
2023-10-17 10:19:36,939 INFO  [Worker$] - worker-text-a: done

I have tried a few attempts but still cannot get it to log an error & kill the proxy intermediate actor between the Worker & the Manager - so thought this would be the best way to reach you. Apologies if not, I am new to this.

@Castro-711
Copy link
Author

I did make an effort to check on the live book discussion but couldn't see anything relating to the code snippets just the text that seemed to have been acknowledged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant