{"action":"created","comment":{"url":"https://api.github.com/repos/broadinstitute/rawls/pulls/comments/63456886","id":63456886,"diff_hunk":"@@ -0,0 +1,229 @@\n+package org.broadinstitute.dsde.rawls.jobexec\n+\n+import java.util.UUID\n+\n+import akka.actor._\n+import akka.pattern._\n+import com.google.api.client.auth.oauth2.Credential\n+import com.typesafe.scalalogging.LazyLogging\n+import org.broadinstitute.dsde.rawls.RawlsException\n+import org.broadinstitute.dsde.rawls.dataaccess._\n+import org.broadinstitute.dsde.rawls.dataaccess.slick._\n+import org.broadinstitute.dsde.rawls.jobexec.WorkflowSubmissionActor._\n+import org.broadinstitute.dsde.rawls.model._\n+import org.broadinstitute.dsde.rawls.util.{MethodWiths, FutureSupport}\n+import _root_.slick.dbio.DBIOAction\n+import _root_.slick.dbio.Effect.Read\n+import spray.http.OAuth2BearerToken\n+import spray.json._\n+import spray.httpx.SprayJsonSupport._\n+\n+\n+import scala.concurrent.{Future, ExecutionContext}\n+import scala.concurrent.duration.FiniteDuration\n+import scala.util.{Success, Failure}\n+\n+\n+object WorkflowSubmissionActor {\n+  def props(dataSource: SlickDataSource,\n+            methodRepoDAO: MethodRepoDAO,\n+            googleServicesDAO: GoogleServicesDAO,\n+            executionServiceDAO: ExecutionServiceDAO,\n+            batchSize: Int,\n+            credential: Credential,\n+            pollInterval: FiniteDuration): Props = {\n+    Props(new WorkflowSubmissionActor(dataSource, methodRepoDAO, googleServicesDAO, executionServiceDAO, batchSize, credential, pollInterval))\n+  }\n+\n+  sealed trait WorkflowSubmissionMessage\n+  case object LookForWorkflows extends WorkflowSubmissionMessage\n+  case class SubmitWorkflowBatch(workflowIds: Seq[Long]) extends WorkflowSubmissionMessage\n+\n+}\n+\n+class WorkflowSubmissionActor(val dataSource: SlickDataSource,\n+                              val methodRepoDAO: MethodRepoDAO,\n+                              val googleServicesDAO: GoogleServicesDAO,\n+                              val executionServiceDAO: ExecutionServiceDAO,\n+                              val batchSize: Int,\n+                              val credential: Credential,\n+                              val pollInterval: FiniteDuration) extends Actor with WorkflowSubmission with LazyLogging {\n+\n+  import context._\n+\n+  scheduleNextWorkflowQuery\n+\n+  override def receive = {\n+    case LookForWorkflows =>\n+      getUnlaunchedWorkflowBatch() pipeTo self\n+    case SubmitWorkflowBatch(workflowIds) =>\n+      submitWorkflowBatch(workflowIds) pipeTo self\n+\n+    case Status.Failure(t) =>\n+      logger.error(t.getMessage)\n+      scheduleNextWorkflowQuery\n+  }\n+\n+  def scheduleNextWorkflowQuery: Cancellable = {\n+    system.scheduler.scheduleOnce(pollInterval, self, LookForWorkflows)\n+  }\n+}\n+\n+trait WorkflowSubmission extends FutureSupport with LazyLogging with MethodWiths {\n+  val dataSource: SlickDataSource\n+  val methodRepoDAO: MethodRepoDAO\n+  val googleServicesDAO: GoogleServicesDAO\n+  val executionServiceDAO: ExecutionServiceDAO\n+  val batchSize: Int\n+  val credential: Credential\n+  val pollInterval: FiniteDuration\n+\n+  import dataSource.dataAccess.driver.api._\n+\n+  //Get a blob of unlaunched workflows, flip their status, and queue them for submission.\n+  def getUnlaunchedWorkflowBatch()(implicit executionContext: ExecutionContext): Future[WorkflowSubmissionMessage] = {\n+    val unlaunchedWfOptF = dataSource.inTransaction { dataAccess =>\n+      //grab a bunch of unsubmitted workflows\n+      dataAccess.workflowQuery.findUnsubmittedWorkflows().take(batchSize).result map { wfRecs =>\n+        if (wfRecs.nonEmpty) wfRecs\n+        else {\n+          //they should also all have the same submission ID\n+          val wfsWithASingleSubmission = wfRecs.filter(_.submissionId == wfRecs.head.submissionId)\n+          //instead: on update, if we don't get the right number back, roll back the txn\n+          //TODO: biden has an incoming change here, with optimistic locking\n+          dataAccess.workflowQuery.batchUpdateStatus(wfsWithASingleSubmission.map(_.id), WorkflowStatuses.Launching)\n+          wfsWithASingleSubmission\n+        }\n+      }\n+    }\n+\n+    //if we find any, next step is to submit them. otherwise, look again.\n+    unlaunchedWfOptF.map {\n+      case workflowRecs if workflowRecs.nonEmpty => SubmitWorkflowBatch(workflowRecs.map(_.id))\n+      case _ => LookForWorkflows","path":"src/main/scala/org/broadinstitute/dsde/rawls/jobexec/WorkflowSubmissionActor.scala","position":103,"original_position":103,"commit_id":"cb49fe3d5ff07eea6497644c02b16b57b3f57e2a","original_commit_id":"196474f508fcc58d0e417b4b8c06306c1065ae7d","user":{"login":"helgridly","id":775136,"avatar_url":"https://avatars.githubusercontent.com/u/775136?v=3","gravatar_id":"","url":"https://api.github.com/users/helgridly","html_url":"https://github.com/helgridly","followers_url":"https://api.github.com/users/helgridly/followers","following_url":"https://api.github.com/users/helgridly/following{/other_user}","gists_url":"https://api.github.com/users/helgridly/gists{/gist_id}","starred_url":"https://api.github.com/users/helgridly/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/helgridly/subscriptions","organizations_url":"https://api.github.com/users/helgridly/orgs","repos_url":"https://api.github.com/users/helgridly/repos","events_url":"https://api.github.com/users/helgridly/events{/privacy}","received_events_url":"https://api.github.com/users/helgridly/received_events","type":"User","site_admin":false},"body":"Great catch.","created_at":"2016-05-17T02:28:46Z","updated_at":"2016-05-17T02:28:46Z","html_url":"https://github.com/broadinstitute/rawls/pull/425#discussion_r63456886","pull_request_url":"https://api.github.com/repos/broadinstitute/rawls/pulls/425","_links":{"self":{"href":"https://api.github.com/repos/broadinstitute/rawls/pulls/comments/63456886"},"html":{"href":"https://github.com/broadinstitute/rawls/pull/425#discussion_r63456886"},"pull_request":{"href":"https://api.github.com/repos/broadinstitute/rawls/pulls/425"}}},"pull_request":{"url":"https://api.github.com/repos/broadinstitute/rawls/pulls/425","id":70079044,"html_url":"https://github.com/broadinstitute/rawls/pull/425","diff_url":"https://github.com/broadinstitute/rawls/pull/425.diff","patch_url":"https://github.com/broadinstitute/rawls/pull/425.patch","issue_url":"https://api.github.com/repos/broadinstitute/rawls/issues/425","number":425,"state":"open","locked":false,"title":"[NOMERGEY] 606 workflow submission actor","user":{"login":"dvoet","id":1521333,"avatar_url":"https://avatars.githubusercontent.com/u/1521333?v=3","gravatar_id":"","url":"https://api.github.com/users/dvoet","html_url":"https://github.com/dvoet","followers_url":"https://api.github.com/users/dvoet/followers","following_url":"https://api.github.com/users/dvoet/following{/other_user}","gists_url":"https://api.github.com/users/dvoet/gists{/gist_id}","starred_url":"https://api.github.com/users/dvoet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dvoet/subscriptions","organizations_url":"https://api.github.com/users/dvoet/orgs","repos_url":"https://api.github.com/users/dvoet/repos","events_url":"https://api.github.com/users/dvoet/events{/privacy}","received_events_url":"https://api.github.com/users/dvoet/received_events","type":"User","site_admin":false},"body":"PR to give intermediate feedback to The President","created_at":"2016-05-14T02:13:31Z","updated_at":"2016-05-17T02:28:46Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":{"login":"helgridly","id":775136,"avatar_url":"https://avatars.githubusercontent.com/u/775136?v=3","gravatar_id":"","url":"https://api.github.com/users/helgridly","html_url":"https://github.com/helgridly","followers_url":"https://api.github.com/users/helgridly/followers","following_url":"https://api.github.com/users/helgridly/following{/other_user}","gists_url":"https://api.github.com/users/helgridly/gists{/gist_id}","starred_url":"https://api.github.com/users/helgridly/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/helgridly/subscriptions","organizations_url":"https://api.github.com/users/helgridly/orgs","repos_url":"https://api.github.com/users/helgridly/repos","events_url":"https://api.github.com/users/helgridly/events{/privacy}","received_events_url":"https://api.github.com/users/helgridly/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/broadinstitute/rawls/pulls/425/commits","review_comments_url":"https://api.github.com/repos/broadinstitute/rawls/pulls/425/comments","review_comment_url":"https://api.github.com/repos/broadinstitute/rawls/pulls/comments{/number}","comments_url":"https://api.github.com/repos/broadinstitute/rawls/issues/425/comments","statuses_url":"https://api.github.com/repos/broadinstitute/rawls/statuses/cb49fe3d5ff07eea6497644c02b16b57b3f57e2a","head":{"label":"broadinstitute:606_workflow_submission_actor","ref":"606_workflow_submission_actor","sha":"cb49fe3d5ff07eea6497644c02b16b57b3f57e2a","user":{"login":"broadinstitute","id":393552,"avatar_url":"https://avatars.githubusercontent.com/u/393552?v=3","gravatar_id":"","url":"https://api.github.com/users/broadinstitute","html_url":"https://github.com/broadinstitute","followers_url":"https://api.github.com/users/broadinstitute/followers","following_url":"https://api.github.com/users/broadinstitute/following{/other_user}","gists_url":"https://api.github.com/users/broadinstitute/gists{/gist_id}","starred_url":"https://api.github.com/users/broadinstitute/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/broadinstitute/subscriptions","organizations_url":"https://api.github.com/users/broadinstitute/orgs","repos_url":"https://api.github.com/users/broadinstitute/repos","events_url":"https://api.github.com/users/broadinstitute/events{/privacy}","received_events_url":"https://api.github.com/users/broadinstitute/received_events","type":"Organization","site_admin":false},"repo":{"id":34129770,"name":"rawls","full_name":"broadinstitute/rawls","owner":{"login":"broadinstitute","id":393552,"avatar_url":"https://avatars.githubusercontent.com/u/393552?v=3","gravatar_id":"","url":"https://api.github.com/users/broadinstitute","html_url":"https://github.com/broadinstitute","followers_url":"https://api.github.com/users/broadinstitute/followers","following_url":"https://api.github.com/users/broadinstitute/following{/other_user}","gists_url":"https://api.github.com/users/broadinstitute/gists{/gist_id}","starred_url":"https://api.github.com/users/broadinstitute/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/broadinstitute/subscriptions","organizations_url":"https://api.github.com/users/broadinstitute/orgs","repos_url":"https://api.github.com/users/broadinstitute/repos","events_url":"https://api.github.com/users/broadinstitute/events{/privacy}","received_events_url":"https://api.github.com/users/broadinstitute/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/broadinstitute/rawls","description":"Rawls service for DSDE","fork":false,"url":"https://api.github.com/repos/broadinstitute/rawls","forks_url":"https://api.github.com/repos/broadinstitute/rawls/forks","keys_url":"https://api.github.com/repos/broadinstitute/rawls/keys{/key_id}","collaborators_url":"https://api.github.com/repos/broadinstitute/rawls/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/broadinstitute/rawls/teams","hooks_url":"https://api.github.com/repos/broadinstitute/rawls/hooks","issue_events_url":"https://api.github.com/repos/broadinstitute/rawls/issues/events{/number}","events_url":"https://api.github.com/repos/broadinstitute/rawls/events","assignees_url":"https://api.github.com/repos/broadinstitute/rawls/assignees{/user}","branches_url":"https://api.github.com/repos/broadinstitute/rawls/branches{/branch}","tags_url":"https://api.github.com/repos/broadinstitute/rawls/tags","blobs_url":"https://api.github.com/repos/broadinstitute/rawls/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/broadinstitute/rawls/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/broadinstitute/rawls/git/refs{/sha}","trees_url":"https://api.github.com/repos/broadinstitute/rawls/git/trees{/sha}","statuses_url":"https://api.github.com/repos/broadinstitute/rawls/statuses/{sha}","languages_url":"https://api.github.com/repos/broadinstitute/rawls/languages","stargazers_url":"https://api.github.com/repos/broadinstitute/rawls/stargazers","contributors_url":"https://api.github.com/repos/broadinstitute/rawls/contributors","subscribers_url":"https://api.github.com/repos/broadinstitute/rawls/subscribers","subscription_url":"https://api.github.com/repos/broadinstitute/rawls/subscription","commits_url":"https://api.github.com/repos/broadinstitute/rawls/commits{/sha}","git_commits_url":"https://api.github.com/repos/broadinstitute/rawls/git/commits{/sha}","comments_url":"https://api.github.com/repos/broadinstitute/rawls/comments{/number}","issue_comment_url":"https://api.github.com/repos/broadinstitute/rawls/issues/comments{/number}","contents_url":"https://api.github.com/repos/broadinstitute/rawls/contents/{+path}","compare_url":"https://api.github.com/repos/broadinstitute/rawls/compare/{base}...{head}","merges_url":"https://api.github.com/repos/broadinstitute/rawls/merges","archive_url":"https://api.github.com/repos/broadinstitute/rawls/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/broadinstitute/rawls/downloads","issues_url":"https://api.github.com/repos/broadinstitute/rawls/issues{/number}","pulls_url":"https://api.github.com/repos/broadinstitute/rawls/pulls{/number}","milestones_url":"https://api.github.com/repos/broadinstitute/rawls/milestones{/number}","notifications_url":"https://api.github.com/repos/broadinstitute/rawls/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/broadinstitute/rawls/labels{/name}","releases_url":"https://api.github.com/repos/broadinstitute/rawls/releases{/id}","deployments_url":"https://api.github.com/repos/broadinstitute/rawls/deployments","created_at":"2015-04-17T17:16:07Z","updated_at":"2016-03-04T19:30:59Z","pushed_at":"2016-05-17T02:22:59Z","git_url":"git://github.com/broadinstitute/rawls.git","ssh_url":"git@github.com:broadinstitute/rawls.git","clone_url":"https://github.com/broadinstitute/rawls.git","svn_url":"https://github.com/broadinstitute/rawls","homepage":null,"size":4047,"stargazers_count":5,"watchers_count":5,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":4,"forks":1,"open_issues":4,"watchers":5,"default_branch":"develop"}},"base":{"label":"broadinstitute:develop","ref":"develop","sha":"823628cb33c49091fa81057a3c7b2cee716ff620","user":{"login":"broadinstitute","id":393552,"avatar_url":"https://avatars.githubusercontent.com/u/393552?v=3","gravatar_id":"","url":"https://api.github.com/users/broadinstitute","html_url":"https://github.com/broadinstitute","followers_url":"https://api.github.com/users/broadinstitute/followers","following_url":"https://api.github.com/users/broadinstitute/following{/other_user}","gists_url":"https://api.github.com/users/broadinstitute/gists{/gist_id}","starred_url":"https://api.github.com/users/broadinstitute/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/broadinstitute/subscriptions","organizations_url":"https://api.github.com/users/broadinstitute/orgs","repos_url":"https://api.github.com/users/broadinstitute/repos","events_url":"https://api.github.com/users/broadinstitute/events{/privacy}","received_events_url":"https://api.github.com/users/broadinstitute/received_events","type":"Organization","site_admin":false},"repo":{"id":34129770,"name":"rawls","full_name":"broadinstitute/rawls","owner":{"login":"broadinstitute","id":393552,"avatar_url":"https://avatars.githubusercontent.com/u/393552?v=3","gravatar_id":"","url":"https://api.github.com/users/broadinstitute","html_url":"https://github.com/broadinstitute","followers_url":"https://api.github.com/users/broadinstitute/followers","following_url":"https://api.github.com/users/broadinstitute/following{/other_user}","gists_url":"https://api.github.com/users/broadinstitute/gists{/gist_id}","starred_url":"https://api.github.com/users/broadinstitute/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/broadinstitute/subscriptions","organizations_url":"https://api.github.com/users/broadinstitute/orgs","repos_url":"https://api.github.com/users/broadinstitute/repos","events_url":"https://api.github.com/users/broadinstitute/events{/privacy}","received_events_url":"https://api.github.com/users/broadinstitute/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/broadinstitute/rawls","description":"Rawls service for DSDE","fork":false,"url":"https://api.github.com/repos/broadinstitute/rawls","forks_url":"https://api.github.com/repos/broadinstitute/rawls/forks","keys_url":"https://api.github.com/repos/broadinstitute/rawls/keys{/key_id}","collaborators_url":"https://api.github.com/repos/broadinstitute/rawls/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/broadinstitute/rawls/teams","hooks_url":"https://api.github.com/repos/broadinstitute/rawls/hooks","issue_events_url":"https://api.github.com/repos/broadinstitute/rawls/issues/events{/number}","events_url":"https://api.github.com/repos/broadinstitute/rawls/events","assignees_url":"https://api.github.com/repos/broadinstitute/rawls/assignees{/user}","branches_url":"https://api.github.com/repos/broadinstitute/rawls/branches{/branch}","tags_url":"https://api.github.com/repos/broadinstitute/rawls/tags","blobs_url":"https://api.github.com/repos/broadinstitute/rawls/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/broadinstitute/rawls/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/broadinstitute/rawls/git/refs{/sha}","trees_url":"https://api.github.com/repos/broadinstitute/rawls/git/trees{/sha}","statuses_url":"https://api.github.com/repos/broadinstitute/rawls/statuses/{sha}","languages_url":"https://api.github.com/repos/broadinstitute/rawls/languages","stargazers_url":"https://api.github.com/repos/broadinstitute/rawls/stargazers","contributors_url":"https://api.github.com/repos/broadinstitute/rawls/contributors","subscribers_url":"https://api.github.com/repos/broadinstitute/rawls/subscribers","subscription_url":"https://api.github.com/repos/broadinstitute/rawls/subscription","commits_url":"https://api.github.com/repos/broadinstitute/rawls/commits{/sha}","git_commits_url":"https://api.github.com/repos/broadinstitute/rawls/git/commits{/sha}","comments_url":"https://api.github.com/repos/broadinstitute/rawls/comments{/number}","issue_comment_url":"https://api.github.com/repos/broadinstitute/rawls/issues/comments{/number}","contents_url":"https://api.github.com/repos/broadinstitute/rawls/contents/{+path}","compare_url":"https://api.github.com/repos/broadinstitute/rawls/compare/{base}...{head}","merges_url":"https://api.github.com/repos/broadinstitute/rawls/merges","archive_url":"https://api.github.com/repos/broadinstitute/rawls/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/broadinstitute/rawls/downloads","issues_url":"https://api.github.com/repos/broadinstitute/rawls/issues{/number}","pulls_url":"https://api.github.com/repos/broadinstitute/rawls/pulls{/number}","milestones_url":"https://api.github.com/repos/broadinstitute/rawls/milestones{/number}","notifications_url":"https://api.github.com/repos/broadinstitute/rawls/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/broadinstitute/rawls/labels{/name}","releases_url":"https://api.github.com/repos/broadinstitute/rawls/releases{/id}","deployments_url":"https://api.github.com/repos/broadinstitute/rawls/deployments","created_at":"2015-04-17T17:16:07Z","updated_at":"2016-03-04T19:30:59Z","pushed_at":"2016-05-17T02:22:59Z","git_url":"git://github.com/broadinstitute/rawls.git","ssh_url":"git@github.com:broadinstitute/rawls.git","clone_url":"https://github.com/broadinstitute/rawls.git","svn_url":"https://github.com/broadinstitute/rawls","homepage":null,"size":4047,"stargazers_count":5,"watchers_count":5,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":4,"forks":1,"open_issues":4,"watchers":5,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/broadinstitute/rawls/pulls/425"},"html":{"href":"https://github.com/broadinstitute/rawls/pull/425"},"issue":{"href":"https://api.github.com/repos/broadinstitute/rawls/issues/425"},"comments":{"href":"https://api.github.com/repos/broadinstitute/rawls/issues/425/comments"},"review_comments":{"href":"https://api.github.com/repos/broadinstitute/rawls/pulls/425/comments"},"review_comment":{"href":"https://api.github.com/repos/broadinstitute/rawls/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/broadinstitute/rawls/pulls/425/commits"},"statuses":{"href":"https://api.github.com/repos/broadinstitute/rawls/statuses/cb49fe3d5ff07eea6497644c02b16b57b3f57e2a"}}}}