Skip to content

Frikanalen/jukebox

Repository files navigation

jukebox

Note: This generates the schedule for Frikanalen v3, currently running on beta.frikanalen.no. Until v2 is decommissioned, schedule is still generated by these scripts, invoked by these cron jobs.

Coverage

This schedules videos on the Frikanalen linear schedule.

It weights candidates videos according to various criteria, like so:

  const entries = fillPeriod(startAt, endAt, {
    weightings: [
      { criteria: "notRecentlySeenFromSameOrganization", multiplier: 100 },
      { criteria: "notScheduled", multiplier: 30 },
      { criteria: "notRecentlySeen", multiplier: 20 },
      { criteria: "notSeenThisWeek", multiplier: 10 },
      { criteria: "notSeenToday", multiplier: 10 },
      { criteria: "isRecent", multiplier: 2 },
      { criteria: "rand", multiplier: 1 },
    ],
    videos,
  })

To get to an MVP of Frikanalen v3.0 as soon as possible while retaining flexibility for future support for eg. live events, the schedule is split into multiple layers.

The previous generation of software had limited to no support for live events, and in migrations the schedule is copied directly into the jukebox table.

The jukebox generates the "background layer", currently the only one in the database.

In the future, user-scheduled videos and live events will occupy other database tables, which will then override whatever is defined by the jukebox.

Requirements / configuration

Set the environment variable FK_API_KEY to the same value as seen by toches, and set FK_API to an URL pointing to it.

Copy dev-env to .env for standard defaults for development.

Cron job

apiVersion: batch/v1
kind: CronJob
metadata:
  name: jukebox
  namespace: beta
spec:
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - env:
            - name: FK_API
              value: https://beta.frikanalen.no/api/v2
            - name: FK_API_KEY
              valueFrom:
                secretKeyRef:
                  key: FK_API_KEY
                  name: fk-api-key
            image: frikanalen/jukebox-v2:latest
            name: jukebox
  schedule: 00 22 * * *
  successfulJobsHistoryLimit: 3
  suspend: false