equal
deleted
inserted
replaced
457 stmt.bool(4) = message.verbose |
457 stmt.bool(4) = message.verbose |
458 stmt.string(5) = build_uuid |
458 stmt.string(5) = build_uuid |
459 }) |
459 }) |
460 } |
460 } |
461 |
461 |
462 def sync_progress(db: SQL.Database, build_uuid: String, build_progress: Progress): Unit = { |
462 def sync_progress( |
|
463 db: SQL.Database, |
|
464 seen: Long, |
|
465 build_uuid: String, |
|
466 build_progress: Progress |
|
467 ): (Progress_Messages, Boolean) = { |
|
468 require(build_uuid.nonEmpty) |
|
469 |
|
470 val messages = read_progress(db, seen = seen, build_uuid = build_uuid) |
|
471 |
463 val stopped_db = |
472 val stopped_db = |
464 db.execute_query_statementO[Boolean]( |
473 db.execute_query_statementO[Boolean]( |
465 Base.table.select(List(Base.progress_stopped), |
474 Base.table.select(List(Base.progress_stopped), |
466 sql = SQL.where(Base.build_uuid.equal(build_uuid))), |
475 sql = SQL.where(Base.build_uuid.equal(build_uuid))), |
467 res => res.bool(Base.progress_stopped) |
476 res => res.bool(Base.progress_stopped) |
475 |
484 |
476 val stopped = build_progress.stopped |
485 val stopped = build_progress.stopped |
477 |
486 |
478 if (stopped_db && !stopped) build_progress.stop() |
487 if (stopped_db && !stopped) build_progress.stop() |
479 if (stopped && !stopped_db) stop_db() |
488 if (stopped && !stopped_db) stop_db() |
|
489 |
|
490 (messages, messages.isEmpty && stopped_db == stopped) |
480 } |
491 } |
481 |
492 |
482 |
493 |
483 /* workers */ |
494 /* workers */ |
484 |
495 |
821 protected def synchronized_database[A](body: => A): A = |
832 protected def synchronized_database[A](body: => A): A = |
822 synchronized { |
833 synchronized { |
823 _database match { |
834 _database match { |
824 case None => body |
835 case None => body |
825 case Some(db) => |
836 case Some(db) => |
826 db.transaction_lock(Build_Process.Data.all_tables) { |
837 @tailrec def loop(): A = { |
827 Build_Process.Data.sync_progress(db, build_uuid, build_progress) |
838 val sync_progress = |
828 body |
839 db.transaction_lock(Build_Process.Data.all_tables) { |
|
840 val (messages, sync) = |
|
841 Build_Process.Data.sync_progress( |
|
842 db, _state.progress_seen, build_uuid, build_progress) |
|
843 if (sync) Left(body) else Right(messages) |
|
844 } |
|
845 sync_progress match { |
|
846 case Left(res) => res |
|
847 case Right(messages) => |
|
848 for ((message_serial, message) <- messages) { |
|
849 _state = _state.progress_serial(message_serial = message_serial) |
|
850 if (build_progress.do_output(message)) build_progress.output(message) |
|
851 } |
|
852 loop() |
|
853 } |
829 } |
854 } |
|
855 loop() |
830 } |
856 } |
831 } |
857 } |
832 |
858 |
833 private def sync_database(): Unit = |
859 private def sync_database(): Unit = |
834 synchronized_database { |
860 synchronized_database { |