more work on relay
parent
6620e02688
commit
85da7253d0
|
@ -24,11 +24,7 @@ case class Relay(
|
||||||
if (s.isEmpty) "-" else s
|
if (s.isEmpty) "-" else s
|
||||||
}
|
}
|
||||||
|
|
||||||
def setSync(v: Boolean) = copy(
|
def setSync(v: Boolean) = copy(sync = sync set v)
|
||||||
sync = sync.copy(
|
|
||||||
until = v option DateTime.now.plusHours(3)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
override def toString = s"id:$id sync:$sync"
|
override def toString = s"id:$id sync:$sync"
|
||||||
}
|
}
|
||||||
|
@ -44,6 +40,11 @@ object Relay {
|
||||||
def seconds: Option[Int] = until map { until =>
|
def seconds: Option[Int] = until map { until =>
|
||||||
(until.getSeconds - nowSeconds).toInt
|
(until.getSeconds - nowSeconds).toInt
|
||||||
} filter (0<)
|
} filter (0<)
|
||||||
|
|
||||||
|
def set(v: Boolean) = copy(
|
||||||
|
until = v option DateTime.now.plusHours(3),
|
||||||
|
log = SyncLog(Vector.empty)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
object Sync {
|
object Sync {
|
||||||
|
|
|
@ -23,7 +23,7 @@ private final class RelayFetch(
|
||||||
case object Tick
|
case object Tick
|
||||||
|
|
||||||
def scheduleNext =
|
def scheduleNext =
|
||||||
context.system.scheduler.scheduleOnce(3 seconds, self, Tick)
|
context.system.scheduler.scheduleOnce(5 seconds, self, Tick)
|
||||||
|
|
||||||
def receive = {
|
def receive = {
|
||||||
|
|
||||||
|
@ -34,10 +34,10 @@ private final class RelayFetch(
|
||||||
|
|
||||||
case Tick =>
|
case Tick =>
|
||||||
val startAt = nowMillis
|
val startAt = nowMillis
|
||||||
getSyncable().flatMap {
|
getSyncable().map(_ filter RelayFetch.shouldFetchNow).flatMap {
|
||||||
_.map { relay =>
|
_.map { relay =>
|
||||||
RelayFetch(relay.sync.upstream)
|
RelayFetch(relay.sync.upstream)
|
||||||
.withTimeout(3 seconds, LilaException(s"Request timeout"))(context.system) flatMap {
|
.withTimeout(3 seconds, LilaException("Request timeout"))(context.system) flatMap {
|
||||||
sync(relay, _)
|
sync(relay, _)
|
||||||
} flatMap { res =>
|
} flatMap { res =>
|
||||||
addLog(relay.id, SyncLog.Event(none, DateTime.now)) inject res
|
addLog(relay.id, SyncLog.Event(none, DateTime.now)) inject res
|
||||||
|
@ -53,6 +53,10 @@ private final class RelayFetch(
|
||||||
|
|
||||||
private object RelayFetch {
|
private object RelayFetch {
|
||||||
|
|
||||||
|
def shouldFetchNow(r: Relay) = !r.sync.log.alwaysFails || {
|
||||||
|
r.sync.log.updatedAt ?? { DateTime.now.minusSeconds(30).isAfter }
|
||||||
|
}
|
||||||
|
|
||||||
import Relay.Sync.Upstream
|
import Relay.Sync.Upstream
|
||||||
import RelaySync.MultiPgn
|
import RelaySync.MultiPgn
|
||||||
|
|
||||||
|
|
|
@ -44,14 +44,15 @@ private final class RelaySync(
|
||||||
}
|
}
|
||||||
case (found, _) => found
|
case (found, _) => found
|
||||||
} match {
|
} match {
|
||||||
case (path, None) => // no new nodes were found
|
// fix mainline, and call it a day
|
||||||
!Path.isMainline(chapter.root, path) ?? studyApi.promote(
|
case (path, _) if !Path.isMainline(chapter.root, path) => studyApi.promote(
|
||||||
userId = chapter.ownerId,
|
userId = chapter.ownerId,
|
||||||
studyId = study.id,
|
studyId = study.id,
|
||||||
position = Position(chapter, path).ref,
|
position = Position(chapter, path).ref,
|
||||||
toMainline = true,
|
toMainline = true,
|
||||||
uid = socketUid
|
uid = socketUid
|
||||||
)
|
)
|
||||||
|
case (path, None) => funit // no new nodes were found
|
||||||
case (path, Some(node)) => // append new nodes to the chapter
|
case (path, Some(node)) => // append new nodes to the chapter
|
||||||
lila.common.Future.fold(node.mainline)(Position(chapter, path)) {
|
lila.common.Future.fold(node.mainline)(Position(chapter, path)) {
|
||||||
case (position, n) => studyApi.doAddNode(
|
case (position, n) => studyApi.doAddNode(
|
||||||
|
|
|
@ -5,6 +5,10 @@ import org.joda.time.DateTime
|
||||||
case class SyncLog(events: Vector[SyncLog.Event]) extends AnyVal {
|
case class SyncLog(events: Vector[SyncLog.Event]) extends AnyVal {
|
||||||
|
|
||||||
def isOk = events.lastOption ?? (_.isOk)
|
def isOk = events.lastOption ?? (_.isOk)
|
||||||
|
|
||||||
|
def alwaysFails = events.size == SyncLog.historySize && events.forall(_.isKo)
|
||||||
|
|
||||||
|
def updatedAt = events.lastOption.map(_.at)
|
||||||
}
|
}
|
||||||
|
|
||||||
object SyncLog {
|
object SyncLog {
|
||||||
|
@ -16,5 +20,6 @@ object SyncLog {
|
||||||
at: DateTime
|
at: DateTime
|
||||||
) {
|
) {
|
||||||
def isOk = error.isEmpty
|
def isOk = error.isEmpty
|
||||||
|
def isKo = error.nonEmpty
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
.relay_edit .lichess_game .lichess_ground {
|
.relay_edit .lichess_game .lichess_ground {
|
||||||
margin-bottom: -337px;
|
margin-bottom: -237px;
|
||||||
}
|
}
|
||||||
.relay_edit .relay_wrap {
|
.relay_edit .relay_wrap {
|
||||||
height: 300px;
|
height: 200px;
|
||||||
}
|
}
|
||||||
.relay_edit .relay_wrap h2 {
|
.relay_edit .relay_wrap h2 {
|
||||||
background: #666;
|
background: #666;
|
||||||
|
@ -15,7 +15,7 @@
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-flow: column;
|
flex-flow: column;
|
||||||
border: 1px solid #ccc;
|
border: 1px solid #ccc;
|
||||||
border-width: 0 1px;
|
border-top-width: 0;
|
||||||
}
|
}
|
||||||
.relay_edit .relay .state {
|
.relay_edit .relay .state {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
@ -55,10 +55,12 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.relay_edit .relay .log {
|
.relay_edit .relay .log {
|
||||||
|
overflow-x: hidden;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
|
max-height: 150px;
|
||||||
}
|
}
|
||||||
.relay_edit .relay .log > div {
|
.relay_edit .relay .log > div {
|
||||||
margin: 3px 0;
|
margin: 4px 0;
|
||||||
display: flex;
|
display: flex;
|
||||||
}
|
}
|
||||||
.relay_edit .relay .log time {
|
.relay_edit .relay .log time {
|
||||||
|
|
|
@ -140,6 +140,7 @@ export function view(ctrl): VNode {
|
||||||
const currentChapterSetup = ctrl.root.study.data.chapter.setup;
|
const currentChapterSetup = ctrl.root.study.data.chapter.setup;
|
||||||
|
|
||||||
return dialog.form({
|
return dialog.form({
|
||||||
|
class: 'chapter-new',
|
||||||
onClose() {
|
onClose() {
|
||||||
ctrl.close();
|
ctrl.close();
|
||||||
ctrl.redraw();
|
ctrl.redraw();
|
||||||
|
|
|
@ -22,7 +22,7 @@ function renderLog(log: LogEvent[]) {
|
||||||
}, [
|
}, [
|
||||||
iconTag(err ? 'j' : 'E'),
|
iconTag(err ? 'j' : 'E'),
|
||||||
h('div', [
|
h('div', [
|
||||||
err || 'Synchronisation successful',
|
err || 'Success',
|
||||||
h('time', window.lichess.timeago.absolute(e.at))
|
h('time', window.lichess.timeago.absolute(e.at))
|
||||||
])
|
])
|
||||||
]);
|
]);
|
||||||
|
@ -33,7 +33,7 @@ function stateOn(ctrl: RelayCtrl) {
|
||||||
return h('div.state.on.clickable', {
|
return h('div.state.on.clickable', {
|
||||||
hook: bind('click', _ => ctrl.setSync(false))
|
hook: bind('click', _ => ctrl.setSync(false))
|
||||||
}, [
|
}, [
|
||||||
iconTag('E'),
|
iconTag('B'),
|
||||||
h('div', [
|
h('div', [
|
||||||
'Connected to PGN source',
|
'Connected to PGN source',
|
||||||
h('div.timer', {
|
h('div.timer', {
|
||||||
|
|
|
@ -55,7 +55,7 @@ export default function(data: StudyData, ctrl: AnalyseCtrl, tagTypes: TagTypes,
|
||||||
|
|
||||||
const form: StudyFormCtrl = studyFormCtrl((d, isNew) => {
|
const form: StudyFormCtrl = studyFormCtrl((d, isNew) => {
|
||||||
send("editStudy", d);
|
send("editStudy", d);
|
||||||
if (isNew && data.chapter.setup.variant.key === 'standard' && ctrl.mainline.length === 1 && !data.chapter.setup.fromFen)
|
if (isNew && data.chapter.setup.variant.key === 'standard' && ctrl.mainline.length === 1 && !data.chapter.setup.fromFen && !relay)
|
||||||
chapters.newForm.openInitial();
|
chapters.newForm.openInitial();
|
||||||
}, () => data, redraw, relay);
|
}, () => data, redraw, relay);
|
||||||
|
|
||||||
|
|
|
@ -98,6 +98,7 @@ export function view(ctrl: StudyFormCtrl): VNode {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return dialog.form({
|
return dialog.form({
|
||||||
|
class: 'study-edit',
|
||||||
onClose: function() {
|
onClose: function() {
|
||||||
ctrl.open(false);
|
ctrl.open(false);
|
||||||
ctrl.redraw();
|
ctrl.redraw();
|
||||||
|
@ -108,7 +109,8 @@ export function view(ctrl: StudyFormCtrl): VNode {
|
||||||
hook: bindSubmit(e => {
|
hook: bindSubmit(e => {
|
||||||
const obj: FormData = {};
|
const obj: FormData = {};
|
||||||
'name visibility computer explorer cloneable chat sticky'.split(' ').forEach(n => {
|
'name visibility computer explorer cloneable chat sticky'.split(' ').forEach(n => {
|
||||||
obj[n] = ((e.target as HTMLElement).querySelector('#study-' + n) as HTMLInputElement).value;
|
const el = ((e.target as HTMLElement).querySelector('#study-' + n) as HTMLInputElement);
|
||||||
|
if (el) obj[n] = el.value;
|
||||||
});
|
});
|
||||||
ctrl.save(obj, isNew);
|
ctrl.save(obj, isNew);
|
||||||
}, ctrl.redraw)
|
}, ctrl.redraw)
|
||||||
|
|
Loading…
Reference in New Issue