Skip to content

Commit

Permalink
feat: add basic table housekeeper to deleted data after x days
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Trost <[email protected]>
  • Loading branch information
galexrt committed Dec 5, 2024
1 parent a984b93 commit 546b389
Show file tree
Hide file tree
Showing 17 changed files with 846 additions and 125 deletions.
12 changes: 12 additions & 0 deletions gen/go/proto/resources/common/cron/cron.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package cron

import "time"

const DefaultCronTimeout = 10 * time.Second

func (x *Cronjob) Merge(in *Cronjob) *Cronjob {
x.Schedule = in.Schedule

Expand All @@ -22,6 +26,14 @@ func (x *Cronjob) Merge(in *Cronjob) *Cronjob {
return x
}

func (x *Cronjob) GetRunTimeout() time.Duration {
if x.Timeout == nil {
return DefaultCronTimeout
}

return x.Timeout.AsDuration()
}

func (x *CronjobData) Merge(in *CronjobData) *CronjobData {
x.Data = in.Data

Expand Down
248 changes: 169 additions & 79 deletions gen/go/proto/resources/common/cron/cron.pb.go

Large diffs are not rendered by default.

216 changes: 194 additions & 22 deletions gen/go/proto/resources/common/cron/cron.pb.validate.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions gen/go/proto/services/calendar/calendar.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/fivenet-app/fivenet/pkg/access"
"github.com/fivenet-app/fivenet/pkg/config/appconfig"
"github.com/fivenet-app/fivenet/pkg/events"
"github.com/fivenet-app/fivenet/pkg/housekeeper"
"github.com/fivenet-app/fivenet/pkg/mstlystcdata"
"github.com/fivenet-app/fivenet/pkg/notifi"
"github.com/fivenet-app/fivenet/pkg/perms"
Expand All @@ -33,6 +34,20 @@ var (
tUserProps = table.FivenetUserProps
)

func init() {
housekeeper.AddTable(&housekeeper.Table{
Table: table.FivenetCalendar,
TimestampColumn: table.FivenetCalendar.DeletedAt,
MinDays: 60,
})

housekeeper.AddTable(&housekeeper.Table{
Table: table.FivenetCalendarEntries,
TimestampColumn: table.FivenetCalendarEntries.DeletedAt,
MinDays: 60,
})
}

type Server struct {
CalendarServiceServer

Expand Down
34 changes: 34 additions & 0 deletions gen/go/proto/services/docstore/docstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/fivenet-app/fivenet/pkg/grpc/auth"
"github.com/fivenet-app/fivenet/pkg/grpc/auth/userinfo"
"github.com/fivenet-app/fivenet/pkg/grpc/errswrap"
"github.com/fivenet-app/fivenet/pkg/housekeeper"
"github.com/fivenet-app/fivenet/pkg/html/htmldiffer"
"github.com/fivenet-app/fivenet/pkg/html/htmlsanitizer"
"github.com/fivenet-app/fivenet/pkg/mstlystcdata"
Expand All @@ -38,6 +39,8 @@ import (
const (
DocsDefaultPageSize = 16
DocShortContentLength = 128

housekeeperMinDays = 60
)

var (
Expand All @@ -50,6 +53,37 @@ var (
tDUserAccess = table.FivenetDocumentsUserAccess.AS("user_access")
)

func init() {
housekeeper.AddTable(&housekeeper.Table{
Table: table.FivenetDocuments,
TimestampColumn: table.FivenetDocuments.DeletedAt,
MinDays: housekeeperMinDays,
})

housekeeper.AddTable(&housekeeper.Table{
Table: table.FivenetDocumentsTemplates,
TimestampColumn: table.FivenetDocumentsTemplates.DeletedAt,
MinDays: housekeeperMinDays,
})

housekeeper.AddTable(&housekeeper.Table{
Table: table.FivenetDocumentsComments,
TimestampColumn: table.FivenetDocumentsComments.DeletedAt,
MinDays: housekeeperMinDays,
})

housekeeper.AddTable(&housekeeper.Table{
Table: table.FivenetDocumentsReferences,
TimestampColumn: table.FivenetDocumentsReferences.DeletedAt,
MinDays: housekeeperMinDays,
})
housekeeper.AddTable(&housekeeper.Table{
Table: table.FivenetDocumentsRelations,
TimestampColumn: table.FivenetDocumentsRelations.DeletedAt,
MinDays: housekeeperMinDays,
})
}

type Server struct {
DocStoreServiceServer

Expand Down
4 changes: 2 additions & 2 deletions gen/go/proto/services/docstore/workflow_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ type WorkflowParams struct {

func NewWorkflow(p WorkflowParams) *Workflow {
w := &Workflow{
logger: p.Logger,
logger: p.Logger.Named("docstore.workflow"),
tracer: p.TP.Tracer("docstore_workflow"),
db: p.DB,
notif: p.Notif,
Expand All @@ -71,7 +71,7 @@ func NewWorkflow(p WorkflowParams) *Workflow {
p.LC.Append(fx.StartHook(func(ctx context.Context) error {
if err := p.Cron.RegisterCronjob(ctx, &cron.Cronjob{
Name: "docstore.workflow_run",
Schedule: "*/15 * * * * *", // Every minute
Schedule: "@always", // Every minute
}); err != nil {
return err
}
Expand Down
Loading

0 comments on commit 546b389

Please sign in to comment.