GitHub PullRequestReviewCommentEvent at 2014-09-22 12:42:47
Repository: hercules
Actor: b97pla
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/Molmed/hercules/pulls/comments/17845972","id":17845972,"diff_hunk":"@@ -38,94 +34,105 @@ object EmailNotifierActor extends MasterLookup {\n    * @param clusterClient A reference to a cluster client thorough which the\n    *                      actor will communicate with the rest of the cluster.\n    */\n-  def props(clusterClient: ActorRef): Props = {\n-    Props(new EmailNotifierActor(clusterClient))\n-  }\n-  \n+  def props(): Props = {\n+    Props(new EmailNotifierActor())\n+  }  \n }\n \n-class EmailNotifierActor(\n-  clusterClient: ActorRef) extends NotifierActor {\n+class EmailNotifierActor() extends NotifierActor {\n \n+  var failedNotifications: Set[EmailNotificationUnit] = Set()\n+  var sentNotifications: Set[EmailNotificationUnit] = Set()\n+  var permanentlyFailedNotifications: Set[EmailNotificationUnit] = Set()\n+  \n   import HerculesMainProtocol._\n \n   // Get a EmailNotifierConfig object\n   val emailConfig = EmailNotificationConfig.getEmailNotificationConfig(\n-    context.system.settings.config.getConfig(\"email\")\n+    ConfigFactory.load().getConfig(\"notifications.email\")\n   )\n   // Spawn an executor object that will do the work for us\n   val notifierRouter = context.actorOf(\n     EmailNotifierExecutorActor.props(\n-      emailConfig).withRouter(\n-        RoundRobinRouter(nrOfInstances = 1)\n-    ),\n+      emailConfig),\n     \"EmailNotifierExecutorActor\"\n   )\n \n   import context.dispatcher\n+  import NotificationChannelProtocol._\n+  \n \n-  // Request new work periodically\n-  val requestWork =\n+  // Periodically attempt to resend failed messages up to a limit\n+  val resendFailed =\n     context.system.scheduler.schedule(\n-      10.seconds, \n-      10.seconds, \n-      self,\n-      RequestNotificationUnitMessage()\n-    )\n-\n-\t// Create some artificial tasks\n-\tval createWork =\n-    \tcontext.system.scheduler.schedule(\n-      \t60.seconds, \n-      \t300.seconds, \n-      \tself,\n-      \tSendNotificationUnitMessage(new EmailNotificationUnit(\"Generated work\"))\n-    )\n-\n-\t\n+      Duration.create(emailConfig.retryInterval,\"seconds\"),\n+      Duration.create(emailConfig.retryInterval,\"seconds\"), \n+      self, \n+      {RetryFailedNotificationUnitsMessage()})\n \n   // Make sure that the scheduled event stops if the actors does.\n   override def postStop() = {\n-    requestWork.cancel()\n+    resendFailed.cancel()\n   }\n   \n+  \n   def receive = {\n+\n+    // If we receive an instruction to retry failed messages, iterate over that set and send messages that have not met the limit for maximum number of retries\n+    case _: RetryFailedNotificationUnitsMessage => {\n+      log.debug(self + \" received a RetryFailedNotificationUnitsMessage\")\n+      // Send a notification message and remove the unit from the list\n+      failedNotifications.foreach(\n+        unit => {\n+          self ! SendNotificationUnitMessage(unit)\n+          failedNotifications = failedNotifications.filterNot(u => u == unit)\n+        })\n+    }\n     \n     // We've received a request to send a notification\n-    case message: SendNotificationUnitMessage => {\n-      // Check if the notification unit is an email\n-      message.unit match {\n-        case unit: EmailNotificationUnit => {\n-          log.info(self.getClass().getName() + \" will attempt for the \" + unit.attempts + \" time to deliver \" + unit.getClass().getName() + \" message: \" + unit.message)\n-          // Acknowledge to sender that we will take this\n-          sender ! Acknowledge\n+    case message: SendNotificationUnitMessage => message.unit match {\n+      // Check if the message unit is already an EmailNotificationUnit or if we need to wrap it\n+      case unit: EmailNotificationUnit => {\n+        // Check if the notification unit is in a channel that we will pay attention to\n+        if (emailConfig.channels.contains(message.unit.channel)) {\n+          log.debug(self.getClass.getSimpleName + \" will attempt for the \" + unit.attempts + \" time to deliver \" + unit.getClass.getSimpleName + \" message: \" + unit.message)","path":"src/main/scala/hercules/actors/notifiers/EmailNotifierActor.scala","position":null,"original_position":152,"commit_id":"6cd984c086dbb9bf8e3e3e658dbfaccda9c0b2a4","original_commit_id":"4ba4e05662bc34ceae7f49bb50ff6f2710c07b7b","user":{"login":"b97pla","id":886632,"avatar_url":"https://avatars.githubusercontent.com/u/886632?v=2","gravatar_id":"d806c3ec5f6dc2ee9132b23c933cacfa","url":"https://api.github.com/users/b97pla","html_url":"https://github.com/b97pla","followers_url":"https://api.github.com/users/b97pla/followers","following_url":"https://api.github.com/users/b97pla/following{/other_user}","gists_url":"https://api.github.com/users/b97pla/gists{/gist_id}","starred_url":"https://api.github.com/users/b97pla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/b97pla/subscriptions","organizations_url":"https://api.github.com/users/b97pla/orgs","repos_url":"https://api.github.com/users/b97pla/repos","events_url":"https://api.github.com/users/b97pla/events{/privacy}","received_events_url":"https://api.github.com/users/b97pla/received_events","type":"User","site_admin":false},"body":"Thanks, quite ugly code there. I removed those debug statements and wrapped the receive function with LoggingReceive instead.","created_at":"2014-09-22T12:42:47Z","updated_at":"2014-09-22T12:42:47Z","html_url":"https://github.com/Molmed/hercules/pull/21#discussion_r17845972","pull_request_url":"https://api.github.com/repos/Molmed/hercules/pulls/21","_links":{"self":{"href":"https://api.github.com/repos/Molmed/hercules/pulls/comments/17845972"},"html":{"href":"https://github.com/Molmed/hercules/pull/21#discussion_r17845972"},"pull_request":{"href":"https://api.github.com/repos/Molmed/hercules/pulls/21"}}},"pull_request":{"url":"https://api.github.com/repos/Molmed/hercules/pulls/21","id":21574885,"html_url":"https://github.com/Molmed/hercules/pull/21","diff_url":"https://github.com/Molmed/hercules/pull/21.diff","patch_url":"https://github.com/Molmed/hercules/pull/21.patch","issue_url":"https://api.github.com/repos/Molmed/hercules/issues/21","number":21,"state":"open","locked":false,"title":"Feature/notifications","user":{"login":"b97pla","id":886632,"avatar_url":"https://avatars.githubusercontent.com/u/886632?v=2","gravatar_id":"d806c3ec5f6dc2ee9132b23c933cacfa","url":"https://api.github.com/users/b97pla","html_url":"https://github.com/b97pla","followers_url":"https://api.github.com/users/b97pla/followers","following_url":"https://api.github.com/users/b97pla/following{/other_user}","gists_url":"https://api.github.com/users/b97pla/gists{/gist_id}","starred_url":"https://api.github.com/users/b97pla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/b97pla/subscriptions","organizations_url":"https://api.github.com/users/b97pla/orgs","repos_url":"https://api.github.com/users/b97pla/repos","events_url":"https://api.github.com/users/b97pla/events{/privacy}","received_events_url":"https://api.github.com/users/b97pla/received_events","type":"User","site_admin":false},"body":"- Refactored NotifierManager-EmailActor-EmailExecutorActor interplay\r\n- All HerculesActor now have a member value 'notice' which is a NotifierManager. \r\n- The NotifierManager has four methods: info, progress, warning, critical and calling each method sends a message to the corresponding \"channel\"\r\n- Which channel(s) each notification type listens to is configured in application.conf\r\n  ","created_at":"2014-09-22T12:08:43Z","updated_at":"2014-09-22T12:42:47Z","closed_at":null,"merged_at":null,"merge_commit_sha":"58d552e31bf0d4a278a9a5969892ab26c8e3d82e","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Molmed/hercules/pulls/21/commits","review_comments_url":"https://api.github.com/repos/Molmed/hercules/pulls/21/comments","review_comment_url":"https://api.github.com/repos/Molmed/hercules/pulls/comments/{number}","comments_url":"https://api.github.com/repos/Molmed/hercules/issues/21/comments","statuses_url":"https://api.github.com/repos/Molmed/hercules/statuses/6cd984c086dbb9bf8e3e3e658dbfaccda9c0b2a4","head":{"label":"b97pla:feature/notifications","ref":"feature/notifications","sha":"6cd984c086dbb9bf8e3e3e658dbfaccda9c0b2a4","user":{"login":"b97pla","id":886632,"avatar_url":"https://avatars.githubusercontent.com/u/886632?v=2","gravatar_id":"d806c3ec5f6dc2ee9132b23c933cacfa","url":"https://api.github.com/users/b97pla","html_url":"https://github.com/b97pla","followers_url":"https://api.github.com/users/b97pla/followers","following_url":"https://api.github.com/users/b97pla/following{/other_user}","gists_url":"https://api.github.com/users/b97pla/gists{/gist_id}","starred_url":"https://api.github.com/users/b97pla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/b97pla/subscriptions","organizations_url":"https://api.github.com/users/b97pla/orgs","repos_url":"https://api.github.com/users/b97pla/repos","events_url":"https://api.github.com/users/b97pla/events{/privacy}","received_events_url":"https://api.github.com/users/b97pla/received_events","type":"User","site_admin":false},"repo":{"id":24326083,"name":"hercules","full_name":"b97pla/hercules","owner":{"login":"b97pla","id":886632,"avatar_url":"https://avatars.githubusercontent.com/u/886632?v=2","gravatar_id":"d806c3ec5f6dc2ee9132b23c933cacfa","url":"https://api.github.com/users/b97pla","html_url":"https://github.com/b97pla","followers_url":"https://api.github.com/users/b97pla/followers","following_url":"https://api.github.com/users/b97pla/following{/other_user}","gists_url":"https://api.github.com/users/b97pla/gists{/gist_id}","starred_url":"https://api.github.com/users/b97pla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/b97pla/subscriptions","organizations_url":"https://api.github.com/users/b97pla/orgs","repos_url":"https://api.github.com/users/b97pla/repos","events_url":"https://api.github.com/users/b97pla/events{/privacy}","received_events_url":"https://api.github.com/users/b97pla/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/b97pla/hercules","description":"","fork":true,"url":"https://api.github.com/repos/b97pla/hercules","forks_url":"https://api.github.com/repos/b97pla/hercules/forks","keys_url":"https://api.github.com/repos/b97pla/hercules/keys{/key_id}","collaborators_url":"https://api.github.com/repos/b97pla/hercules/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/b97pla/hercules/teams","hooks_url":"https://api.github.com/repos/b97pla/hercules/hooks","issue_events_url":"https://api.github.com/repos/b97pla/hercules/issues/events{/number}","events_url":"https://api.github.com/repos/b97pla/hercules/events","assignees_url":"https://api.github.com/repos/b97pla/hercules/assignees{/user}","branches_url":"https://api.github.com/repos/b97pla/hercules/branches{/branch}","tags_url":"https://api.github.com/repos/b97pla/hercules/tags","blobs_url":"https://api.github.com/repos/b97pla/hercules/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/b97pla/hercules/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/b97pla/hercules/git/refs{/sha}","trees_url":"https://api.github.com/repos/b97pla/hercules/git/trees{/sha}","statuses_url":"https://api.github.com/repos/b97pla/hercules/statuses/{sha}","languages_url":"https://api.github.com/repos/b97pla/hercules/languages","stargazers_url":"https://api.github.com/repos/b97pla/hercules/stargazers","contributors_url":"https://api.github.com/repos/b97pla/hercules/contributors","subscribers_url":"https://api.github.com/repos/b97pla/hercules/subscribers","subscription_url":"https://api.github.com/repos/b97pla/hercules/subscription","commits_url":"https://api.github.com/repos/b97pla/hercules/commits{/sha}","git_commits_url":"https://api.github.com/repos/b97pla/hercules/git/commits{/sha}","comments_url":"https://api.github.com/repos/b97pla/hercules/comments{/number}","issue_comment_url":"https://api.github.com/repos/b97pla/hercules/issues/comments/{number}","contents_url":"https://api.github.com/repos/b97pla/hercules/contents/{+path}","compare_url":"https://api.github.com/repos/b97pla/hercules/compare/{base}...{head}","merges_url":"https://api.github.com/repos/b97pla/hercules/merges","archive_url":"https://api.github.com/repos/b97pla/hercules/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/b97pla/hercules/downloads","issues_url":"https://api.github.com/repos/b97pla/hercules/issues{/number}","pulls_url":"https://api.github.com/repos/b97pla/hercules/pulls{/number}","milestones_url":"https://api.github.com/repos/b97pla/hercules/milestones{/number}","notifications_url":"https://api.github.com/repos/b97pla/hercules/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/b97pla/hercules/labels{/name}","releases_url":"https://api.github.com/repos/b97pla/hercules/releases{/id}","created_at":"2014-09-22T11:35:48Z","updated_at":"2014-09-22T11:36:10Z","pushed_at":"2014-09-22T12:41:40Z","git_url":"git://github.com/b97pla/hercules.git","ssh_url":"git@github.com:b97pla/hercules.git","clone_url":"https://github.com/b97pla/hercules.git","svn_url":"https://github.com/b97pla/hercules","homepage":null,"size":1482,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"Molmed:master","ref":"master","sha":"ba8cb67b10d8767b5bf7005ec9ad124c5893cb08","user":{"login":"Molmed","id":3587866,"avatar_url":"https://avatars.githubusercontent.com/u/3587866?v=2","gravatar_id":null,"url":"https://api.github.com/users/Molmed","html_url":"https://github.com/Molmed","followers_url":"https://api.github.com/users/Molmed/followers","following_url":"https://api.github.com/users/Molmed/following{/other_user}","gists_url":"https://api.github.com/users/Molmed/gists{/gist_id}","starred_url":"https://api.github.com/users/Molmed/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Molmed/subscriptions","organizations_url":"https://api.github.com/users/Molmed/orgs","repos_url":"https://api.github.com/users/Molmed/repos","events_url":"https://api.github.com/users/Molmed/events{/privacy}","received_events_url":"https://api.github.com/users/Molmed/received_events","type":"Organization","site_admin":false},"repo":{"id":23574151,"name":"hercules","full_name":"Molmed/hercules","owner":{"login":"Molmed","id":3587866,"avatar_url":"https://avatars.githubusercontent.com/u/3587866?v=2","gravatar_id":null,"url":"https://api.github.com/users/Molmed","html_url":"https://github.com/Molmed","followers_url":"https://api.github.com/users/Molmed/followers","following_url":"https://api.github.com/users/Molmed/following{/other_user}","gists_url":"https://api.github.com/users/Molmed/gists{/gist_id}","starred_url":"https://api.github.com/users/Molmed/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Molmed/subscriptions","organizations_url":"https://api.github.com/users/Molmed/orgs","repos_url":"https://api.github.com/users/Molmed/repos","events_url":"https://api.github.com/users/Molmed/events{/privacy}","received_events_url":"https://api.github.com/users/Molmed/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Molmed/hercules","description":"","fork":false,"url":"https://api.github.com/repos/Molmed/hercules","forks_url":"https://api.github.com/repos/Molmed/hercules/forks","keys_url":"https://api.github.com/repos/Molmed/hercules/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Molmed/hercules/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Molmed/hercules/teams","hooks_url":"https://api.github.com/repos/Molmed/hercules/hooks","issue_events_url":"https://api.github.com/repos/Molmed/hercules/issues/events{/number}","events_url":"https://api.github.com/repos/Molmed/hercules/events","assignees_url":"https://api.github.com/repos/Molmed/hercules/assignees{/user}","branches_url":"https://api.github.com/repos/Molmed/hercules/branches{/branch}","tags_url":"https://api.github.com/repos/Molmed/hercules/tags","blobs_url":"https://api.github.com/repos/Molmed/hercules/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Molmed/hercules/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Molmed/hercules/git/refs{/sha}","trees_url":"https://api.github.com/repos/Molmed/hercules/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Molmed/hercules/statuses/{sha}","languages_url":"https://api.github.com/repos/Molmed/hercules/languages","stargazers_url":"https://api.github.com/repos/Molmed/hercules/stargazers","contributors_url":"https://api.github.com/repos/Molmed/hercules/contributors","subscribers_url":"https://api.github.com/repos/Molmed/hercules/subscribers","subscription_url":"https://api.github.com/repos/Molmed/hercules/subscription","commits_url":"https://api.github.com/repos/Molmed/hercules/commits{/sha}","git_commits_url":"https://api.github.com/repos/Molmed/hercules/git/commits{/sha}","comments_url":"https://api.github.com/repos/Molmed/hercules/comments{/number}","issue_comment_url":"https://api.github.com/repos/Molmed/hercules/issues/comments/{number}","contents_url":"https://api.github.com/repos/Molmed/hercules/contents/{+path}","compare_url":"https://api.github.com/repos/Molmed/hercules/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Molmed/hercules/merges","archive_url":"https://api.github.com/repos/Molmed/hercules/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Molmed/hercules/downloads","issues_url":"https://api.github.com/repos/Molmed/hercules/issues{/number}","pulls_url":"https://api.github.com/repos/Molmed/hercules/pulls{/number}","milestones_url":"https://api.github.com/repos/Molmed/hercules/milestones{/number}","notifications_url":"https://api.github.com/repos/Molmed/hercules/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Molmed/hercules/labels{/name}","releases_url":"https://api.github.com/repos/Molmed/hercules/releases{/id}","created_at":"2014-09-02T10:17:54Z","updated_at":"2014-09-19T12:39:23Z","pushed_at":"2014-09-19T15:21:19Z","git_url":"git://github.com/Molmed/hercules.git","ssh_url":"git@github.com:Molmed/hercules.git","clone_url":"https://github.com/Molmed/hercules.git","svn_url":"https://github.com/Molmed/hercules","homepage":null,"size":1482,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":1,"forks":2,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Molmed/hercules/pulls/21"},"html":{"href":"https://github.com/Molmed/hercules/pull/21"},"issue":{"href":"https://api.github.com/repos/Molmed/hercules/issues/21"},"comments":{"href":"https://api.github.com/repos/Molmed/hercules/issues/21/comments"},"review_comments":{"href":"https://api.github.com/repos/Molmed/hercules/pulls/21/comments"},"review_comment":{"href":"https://api.github.com/repos/Molmed/hercules/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/Molmed/hercules/pulls/21/commits"},"statuses":{"href":"https://api.github.com/repos/Molmed/hercules/statuses/6cd984c086dbb9bf8e3e3e658dbfaccda9c0b2a4"}}}}