git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Commit fa872384db2701c4af5615677115890b31d29e78

display "Waiting for scuttlebot" when scuttlebot is busy or blocked

#597
Matt McKegg committed on 9/29/2017, 3:51:20 AM
Parent: e1dd111deddb93e3dae6c3e8045101a7139ab5db

Files changed

modules/app/html/progress-notifier.jschanged
sbot/index.jschanged
sbot/heartbeat.jsadded
modules/app/html/progress-notifier.jsView
@@ -1,11 +1,13 @@
1-var {computed, when, h} = require('mutant')
1+var {computed, when, h, Value} = require('mutant')
22 var nest = require('depnest')
33 var sustained = require('../../../lib/sustained')
4+var pull = require('pull-stream')
45
56 exports.gives = nest('app.html.progressNotifier')
67
78 exports.needs = nest({
9+ 'sbot.pull.stream': 'first',
810 'progress.html.render': 'first',
911 'progress.obs': {
1012 indexes: 'first',
1113 replicate: 'first',
@@ -17,8 +19,9 @@
1719 return nest('app.html.progressNotifier', function (id) {
1820 var replicateProgress = api.progress.obs.replicate()
1921 var indexes = api.progress.obs.indexes()
2022 var migration = api.progress.obs.migration()
23+ var waiting = Waiting()
2124
2225 var pending = computed(indexes, (progress) => progress.target - progress.current || 0)
2326 var pendingMigration = computed(migration, (progress) => progress.target - progress.current || 0)
2427
@@ -32,31 +35,56 @@
3235 return 1
3336 }
3437 })
3538
36- var hidden = sustained(computed([replicateProgress.incompleteFeeds, pending, pendingMigration], (incomplete, pending, pendingMigration) => {
37- return incomplete < 5 && !pending && !pendingMigration
39+ var hidden = sustained(computed([waiting, replicateProgress.incompleteFeeds, pending, pendingMigration], (waiting, incomplete, pending, pendingMigration) => {
40+ return !waiting && incomplete < 5 && !pending && !pendingMigration
3841 }), 2000)
3942
4043 // HACK: css animations take up WAY TO MUCH cpu, remove from dom when inactive
4144 var displaying = computed(sustained(hidden, 500, x => !x), hidden => !hidden)
4245
4346 return h('div.info', { hidden }, [
4447 h('div.status', [
4548 when(displaying, h('Loading -small', [
46- when(pendingMigration,
47- [h('span.info', 'Upgrading database'), h('progress', { style: {'margin-left': '10px'}, min: 0, max: 1, value: migrationProgress })],
48- when(computed(replicateProgress.incompleteFeeds, (v) => v > 5),
49- [h('span.info', 'Downloading new messages'), h('progress', { style: {'margin-left': '10px'}, min: 0, max: 1, value: downloadProgress })],
50- when(pending, [
51- [h('span.info', 'Indexing database'), h('progress', { style: {'margin-left': '10px'}, min: 0, max: 1, value: indexProgress })]
52- ], 'Scuttling...')
49+ when(waiting, 'Waiting for Scuttlebot...',
50+ when(pendingMigration,
51+ [h('span.info', 'Upgrading database'), h('progress', { style: {'margin-left': '10px'}, min: 0, max: 1, value: migrationProgress })],
52+ when(computed(replicateProgress.incompleteFeeds, (v) => v > 5),
53+ [h('span.info', 'Downloading new messages'), h('progress', { style: {'margin-left': '10px'}, min: 0, max: 1, value: downloadProgress })],
54+ when(pending, [
55+ [h('span.info', 'Indexing database'), h('progress', { style: {'margin-left': '10px'}, min: 0, max: 1, value: indexProgress })]
56+ ], 'Scuttling...')
57+ )
5358 )
5459 )
5560 ]))
5661 ])
5762 ])
5863 })
64+
65+ // scoped
66+
67+ function Waiting () {
68+ var waiting = Value()
69+ var lastTick = Date.now()
70+
71+ pull(
72+ api.sbot.pull.stream(sbot => sbot.patchwork.heartbeat()),
73+ pull.drain((tick) => {
74+ lastTick = Date.now()
75+ waiting.set(false)
76+ })
77+ )
78+
79+ setInterval(function () {
80+ if (lastTick < Date.now() - 1000) {
81+ waiting.set(true)
82+ }
83+ }, 1000)
84+
85+ return waiting
86+ }
5987 }
6088
6189 function clamp (value) {
6290 return Math.min(1, Math.max(0, value)) || 0
sbot/index.jsView
@@ -1,5 +1,6 @@
11 var Channels = require('./channels')
2+var Heartbeat = require('./heartbeat')
23 var Subscriptions = require('./subscriptions')
34 var Roots = require('./roots')
45 var Progress = require('./progress')
56 var Search = require('./search')
@@ -17,8 +18,9 @@
1718 progress: 'source',
1819 recentFeeds: 'source',
1920 getSubscriptions: 'async',
2021 getChannels: 'async',
22+ heartbeat: 'source',
2123 liveBacklinks: {
2224 subscribe: 'sync',
2325 unsubscribe: 'sync',
2426 stream: 'source'
@@ -33,8 +35,9 @@
3335 var search = Search(ssb, config)
3436 var recentFeeds = RecentFeeds(ssb, config)
3537
3638 return {
39+ heartbeat: Heartbeat(ssb, config),
3740 channels: channels.stream,
3841 subscriptions: subscriptions.stream,
3942 roots: roots.read,
4043 latest: roots.latest,
sbot/heartbeat.jsView
@@ -1,0 +1,12 @@
1+var Pushable = require('pull-pushable')
2+module.exports = function (ssb, config) {
3+ return function () {
4+ var stream = Pushable(() => {
5+ clearInterval(timer)
6+ })
7+ var timer = setInterval(function () {
8+ stream.push(Date.now())
9+ }, 500)
10+ return stream
11+ }
12+}

Built with git-ssb-web