mirror of
				https://github.com/TheAnachronism/docspell.git
				synced 2025-10-31 17:50:11 +00:00 
			
		
		
		
	Improve job-queue query to make sure jobs across all states show up
This commit is contained in:
		| @@ -48,7 +48,9 @@ object OJob { | ||||
|  | ||||
|       def queueState(collective: Ident, maxResults: Int): F[CollectiveQueueState] = | ||||
|         store | ||||
|           .transact(QJob.queueStateSnapshot(collective).take(maxResults.toLong)) | ||||
|           .transact( | ||||
|             QJob.queueStateSnapshot(collective, maxResults.toLong) | ||||
|           ) | ||||
|           .map(t => JobDetail(t._1, t._2)) | ||||
|           .compile | ||||
|           .toVector | ||||
|   | ||||
| @@ -21,7 +21,7 @@ object JobQueueRoutes { | ||||
|     HttpRoutes.of { | ||||
|       case GET -> Root / "state" => | ||||
|         for { | ||||
|           js <- backend.job.queueState(user.account.collective, 200) | ||||
|           js <- backend.job.queueState(user.account.collective, 40) | ||||
|           res = Conversions.mkJobQueueState(js) | ||||
|           resp <- Ok(res) | ||||
|         } yield resp | ||||
|   | ||||
| @@ -209,7 +209,8 @@ object QJob { | ||||
|     store.transact(RJob.findFromIds(ids)) | ||||
|  | ||||
|   def queueStateSnapshot( | ||||
|       collective: Ident | ||||
|       collective: Ident, | ||||
|       max: Long | ||||
|   ): Stream[ConnectionIO, (RJob, Vector[RJobLog])] = { | ||||
|     val JC                     = RJob.Columns | ||||
|     val waiting: Set[JobState] = Set(JobState.Waiting, JobState.Stuck, JobState.Scheduled) | ||||
| @@ -218,18 +219,34 @@ object QJob { | ||||
|  | ||||
|     def selectJobs(now: Timestamp): Stream[ConnectionIO, RJob] = { | ||||
|       val refDate = now.minusHours(24) | ||||
|       val sql = selectSimple( | ||||
|  | ||||
|       val runningJobs = (selectSimple( | ||||
|         JC.all, | ||||
|         RJob.table, | ||||
|         and(JC.group.is(collective), JC.state.isOneOf(running.toSeq)) | ||||
|       ) ++ orderBy(JC.submitted.desc)).query[RJob].stream | ||||
|  | ||||
|       val waitingJobs = (selectSimple( | ||||
|         JC.all, | ||||
|         RJob.table, | ||||
|         and( | ||||
|           JC.group.is(collective), | ||||
|           or( | ||||
|             and(JC.state.isOneOf(done.toSeq), JC.submitted.isGt(refDate)), | ||||
|             JC.state.isOneOf((running ++ waiting).toSeq) | ||||
|           ) | ||||
|           JC.state.isOneOf(waiting.toSeq), | ||||
|           JC.submitted.isGt(refDate) | ||||
|         ) | ||||
|       ) | ||||
|       (sql ++ orderBy(JC.submitted.desc)).query[RJob].stream | ||||
|       ) ++ orderBy(JC.submitted.desc)).query[RJob].stream.take(max) | ||||
|  | ||||
|       val doneJobs = (selectSimple( | ||||
|         JC.all, | ||||
|         RJob.table, | ||||
|         and( | ||||
|           JC.group.is(collective), | ||||
|           JC.state.isOneOf(done.toSeq), | ||||
|           JC.submitted.isGt(refDate) | ||||
|         ) | ||||
|       ) ++ orderBy(JC.submitted.desc)).query[RJob].stream.take(max) | ||||
|  | ||||
|       runningJobs ++ waitingJobs ++ doneJobs | ||||
|     } | ||||
|  | ||||
|     def selectLogs(job: RJob): ConnectionIO[Vector[RJobLog]] = | ||||
|   | ||||
		Reference in New Issue
	
	Block a user