Create generic backend process, fix background interdependencies

This refactor was born out of the inter-dependency cycles developing
between the "background" module and just about every other module which
was caused by the background module becoming a dependency of every
module that needed to background work and the fact that the background
module was also supposedly responsible for the logic for processing
those tasks.

Instead the "background" module is now very, very shallow and relies
entirely on the Postgres NOTIFY logic for triggering jobs. There's a new
table, `job` which holds just a type and single row ID.

All told, this means that jobs can be added to the queue as part of the
API-level or platform-level transaction, ensuring atomicity, and
processing coordination is handled by the platform module, which can
depend on anything.
This commit is contained in:
Eli Ribble 2026-03-16 19:52:29 +00:00
parent 3a28151b09
commit 2538638c9d
No known key found for this signature in database
47 changed files with 1553 additions and 1054 deletions

122
db/dbinfo/job.bob.go Normal file
View file

@ -0,0 +1,122 @@
// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package dbinfo
import "github.com/aarondl/opt/null"
var Jobs = Table[
jobColumns,
jobIndexes,
jobForeignKeys,
jobUniques,
jobChecks,
]{
Schema: "",
Name: "job",
Columns: jobColumns{
Created: column{
Name: "created",
DBType: "timestamp without time zone",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
ID: column{
Name: "id",
DBType: "integer",
Default: "nextval('job_id_seq'::regclass)",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
Type: column{
Name: "type_",
DBType: "public.jobtype",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
RowID: column{
Name: "row_id",
DBType: "integer",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
},
Indexes: jobIndexes{
JobPkey: index{
Type: "btree",
Name: "job_pkey",
Columns: []indexColumn{
{
Name: "id",
Desc: null.FromCond(false, true),
IsExpression: false,
},
},
Unique: true,
Comment: "",
NullsFirst: []bool{false},
NullsDistinct: false,
Where: "",
Include: []string{},
},
},
PrimaryKey: &constraint{
Name: "job_pkey",
Columns: []string{"id"},
Comment: "",
},
Comment: "A temporary holding place for jobs that are pushed to backend workers. Once work is completed the job should be deleted",
}
type jobColumns struct {
Created column
ID column
Type column
RowID column
}
func (c jobColumns) AsSlice() []column {
return []column{
c.Created, c.ID, c.Type, c.RowID,
}
}
type jobIndexes struct {
JobPkey index
}
func (i jobIndexes) AsSlice() []index {
return []index{
i.JobPkey,
}
}
type jobForeignKeys struct{}
func (f jobForeignKeys) AsSlice() []foreignKey {
return []foreignKey{}
}
type jobUniques struct{}
func (u jobUniques) AsSlice() []constraint {
return []constraint{}
}
type jobChecks struct{}
func (c jobChecks) AsSlice() []check {
return []check{}
}