Browse Source

feat: attempt to fix any streams marked as unended

pull/3395/head
Gabe Kangas 2 years ago
parent
commit
6aacd7bfce
No known key found for this signature in database
GPG Key ID: 4345B2060657F330
  1. 2
      core/core.go
  2. 4
      core/data/replays.go
  3. 3
      db/query.sql
  4. 9
      db/query.sql.go
  5. 21
      replays/replays.go

2
core/core.go

@ -17,6 +17,7 @@ import (
"github.com/owncast/owncast/core/webhooks" "github.com/owncast/owncast/core/webhooks"
"github.com/owncast/owncast/models" "github.com/owncast/owncast/models"
"github.com/owncast/owncast/notifications" "github.com/owncast/owncast/notifications"
"github.com/owncast/owncast/replays"
"github.com/owncast/owncast/utils" "github.com/owncast/owncast/utils"
"github.com/owncast/owncast/yp" "github.com/owncast/owncast/yp"
) )
@ -58,6 +59,7 @@ func Start() error {
user.SetupUsers() user.SetupUsers()
auth.Setup(data.GetDatastore()) auth.Setup(data.GetDatastore())
replays.Setup()
fileWriter.SetupFileWriterReceiverService(&handler) fileWriter.SetupFileWriterReceiverService(&handler)

4
core/data/replays.go

@ -1,6 +1,8 @@
package data package data
import "database/sql" import (
"database/sql"
)
func createRecordingTables(db *sql.DB) { func createRecordingTables(db *sql.DB) {
createSegmentsTableSQL := `CREATE TABLE IF NOT EXISTS video_segments ( createSegmentsTableSQL := `CREATE TABLE IF NOT EXISTS video_segments (

3
db/query.sql

@ -163,3 +163,6 @@ SELECT id AS clip_id, stream_id, clipped_by, clip_title, timestamp AS clip_times
-- name: GetFinalSegmentForStream :one -- name: GetFinalSegmentForStream :one
SELECT id, stream_id, output_configuration_id, path, relative_timestamp, timestamp FROM video_segments WHERE stream_id = $1 ORDER BY relative_timestamp DESC LIMIT 1; SELECT id, stream_id, output_configuration_id, path, relative_timestamp, timestamp FROM video_segments WHERE stream_id = $1 ORDER BY relative_timestamp DESC LIMIT 1;
-- name: FixUnfinishedStreams :exec
UPDATE streams SET end_time = (SELECT timestamp FROM video_segments WHERE stream_id = streams.id) WHERE end_time IS NULL;

9
db/query.sql.go

@ -205,6 +205,15 @@ func (q *Queries) DoesInboundActivityExist(ctx context.Context, arg DoesInboundA
return count, err return count, err
} }
const fixUnfinishedStreams = `-- name: FixUnfinishedStreams :exec
UPDATE streams SET end_time = (SELECT timestamp FROM video_segments WHERE stream_id = streams.id) WHERE end_time IS NULL
`
func (q *Queries) FixUnfinishedStreams(ctx context.Context) error {
_, err := q.db.ExecContext(ctx, fixUnfinishedStreams)
return err
}
const getAllClips = `-- name: GetAllClips :many const getAllClips = `-- name: GetAllClips :many
SELECT rc.id AS id, rc.clip_title, rc.stream_id, rc.relative_start_time, rc.relative_end_time, (rc.relative_end_time - rc.relative_start_time) AS duration_seconds, rc.timestamp, s.stream_title AS stream_title SELECT rc.id AS id, rc.clip_title, rc.stream_id, rc.relative_start_time, rc.relative_end_time, (rc.relative_end_time - rc.relative_start_time) AS duration_seconds, rc.timestamp, s.stream_title AS stream_title
FROM replay_clips rc FROM replay_clips rc

21
replays/replays.go

@ -0,0 +1,21 @@
package replays
import (
"context"
"github.com/owncast/owncast/core/data"
log "github.com/sirupsen/logrus"
)
// Setup will setup the replay package.
func Setup() {
fixUnfinishedStreams()
}
// fixUnfinishedStreams will find streams with no end time and attempt to
// give them an end time based on the last segment assigned to that stream.
func fixUnfinishedStreams() {
if err := data.GetDatastore().GetQueries().FixUnfinishedStreams(context.Background()); err != nil {
log.Warnln(err)
}
}
Loading…
Cancel
Save