
SocketIO clients can now send a message with `/subscription` event type in order to subscribe to or unsubscribe from job-related updates. These job-related updates themselves aren't sent yet, so this is a change that's impossible to really test. The socketIO code for joining/leaving rooms is called, though.
53 lines
1.8 KiB
Go
53 lines
1.8 KiB
Go
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
package webupdates
|
|
|
|
import (
|
|
"github.com/rs/zerolog/log"
|
|
|
|
"git.blender.org/flamenco/internal/manager/persistence"
|
|
"git.blender.org/flamenco/pkg/api"
|
|
)
|
|
|
|
// NewJobUpdate returns a partial JobUpdate struct for the given job.
|
|
// It only fills in the fields that represent the current state of the job. For
|
|
// example, it omits `PreviousStatus`. The ommitted fields can be filled in by
|
|
// the caller.
|
|
func NewJobUpdate(job *persistence.Job) api.JobUpdate {
|
|
jobUpdate := api.JobUpdate{
|
|
Id: job.UUID,
|
|
Name: &job.Name,
|
|
Updated: job.UpdatedAt,
|
|
Status: job.Status,
|
|
Type: job.JobType,
|
|
Priority: job.Priority,
|
|
}
|
|
return jobUpdate
|
|
}
|
|
|
|
// BroadcastJobUpdate sends the job update to clients.
|
|
func (b *BiDirComms) BroadcastJobUpdate(jobUpdate api.JobUpdate) {
|
|
log.Debug().Interface("jobUpdate", jobUpdate).Msg("socketIO: broadcasting job update")
|
|
b.BroadcastTo(SocketIORoomJobs, SIOEventJobUpdate, jobUpdate)
|
|
}
|
|
|
|
// BroadcastNewJob sends a "new job" notification to clients.
|
|
func (b *BiDirComms) BroadcastNewJob(jobUpdate api.JobUpdate) {
|
|
if jobUpdate.PreviousStatus != nil {
|
|
log.Warn().Interface("jobUpdate", jobUpdate).Msg("socketIO: new jobs should not have a previous state")
|
|
jobUpdate.PreviousStatus = nil
|
|
}
|
|
|
|
log.Debug().Interface("jobUpdate", jobUpdate).Msg("socketIO: broadcasting new job")
|
|
b.BroadcastTo(SocketIORoomJobs, SIOEventJobUpdate, jobUpdate)
|
|
}
|
|
|
|
// roomForJob will return the SocketIO room name for the given job. Clients in
|
|
// this room will receive info scoped to this job, so for example updates to all
|
|
// tasks of this job.
|
|
//
|
|
// Note that `api.JobUpdate`s themselves are sent to all SocketIO clients, and
|
|
// not to this room.
|
|
func roomForJob(jobUUID string) SocketIORoomName {
|
|
return SocketIORoomName("job-" + jobUUID)
|
|
}
|