tenseleyflow/shithub / 86fb145

Browse files

Capture social feed activity

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
86fb1458626bc7f7d62db0eea8c65a48505db021
Parents
3e9cf7e
Tree
31fd8c2

5 changed files

StatusFile+-
M cmd/shithubd/worker.go 3 0
M internal/repos/create.go 15 0
M internal/worker/jobs/push_process.go 15 0
A internal/worker/jobs/trending_compute.go 75 0
M internal/worker/types.go 6 0
cmd/shithubd/worker.gomodified
@@ -129,6 +129,9 @@ var workerCmd = &cobra.Command{
129129
 			BaseURL:        cfg.Auth.BaseURL,
130130
 			UnsubscribeKey: notifUnsubscribeKey(cfg, logger),
131131
 		}))
132
+		p.Register(worker.KindTrendingCompute, jobs.TrendingCompute(jobs.TrendingComputeDeps{
133
+			Pool: pool, Logger: logger,
134
+		}))
132135
 
133136
 		// Webhook delivery (S33). The fan-out drains domain_events
134137
 		// past its own cursor; deliver runs per-row HTTP POSTs;
internal/repos/create.gomodified
@@ -21,6 +21,7 @@ import (
2121
 	"github.com/tenseleyFlow/shithub/internal/infra/storage"
2222
 	"github.com/tenseleyFlow/shithub/internal/issues"
2323
 	issuesdb "github.com/tenseleyFlow/shithub/internal/issues/sqlc"
24
+	"github.com/tenseleyFlow/shithub/internal/notif"
2425
 	repogit "github.com/tenseleyFlow/shithub/internal/repos/git"
2526
 	reposdb "github.com/tenseleyFlow/shithub/internal/repos/sqlc"
2627
 	"github.com/tenseleyFlow/shithub/internal/repos/templates"
@@ -269,6 +270,20 @@ func Create(ctx context.Context, deps Deps, p Params) (Result, error) {
269270
 	}
270271
 	committed = true
271272
 
273
+	if err := notif.Emit(ctx, deps.Pool, notif.Event{
274
+		ActorUserID: p.ActorUserID,
275
+		Kind:        "repo_created",
276
+		RepoID:      row.ID,
277
+		SourceKind:  "repo",
278
+		SourceID:    row.ID,
279
+		Public:      p.Visibility == "public",
280
+		Extra: map[string]any{
281
+			"repo_name": p.Name,
282
+		},
283
+	}); err != nil && deps.Logger != nil {
284
+		deps.Logger.WarnContext(ctx, "repos: emit repo_created", "repo_id", row.ID, "error", err)
285
+	}
286
+
272287
 	if err := deps.Audit.Record(ctx, deps.Pool, p.ActorUserID,
273288
 		audit.ActionRepoCreated, audit.TargetRepo, row.ID, map[string]any{
274289
 			"name":       p.Name,
internal/worker/jobs/push_process.gomodified
@@ -25,6 +25,7 @@ import (
2525
 	pullsdb "github.com/tenseleyFlow/shithub/internal/pulls/sqlc"
2626
 	gitops "github.com/tenseleyFlow/shithub/internal/repos/git"
2727
 	reposdb "github.com/tenseleyFlow/shithub/internal/repos/sqlc"
28
+	"github.com/tenseleyFlow/shithub/internal/social"
2829
 	usersdb "github.com/tenseleyFlow/shithub/internal/users/sqlc"
2930
 	"github.com/tenseleyFlow/shithub/internal/worker"
3031
 	workerdb "github.com/tenseleyFlow/shithub/internal/worker/sqlc"
@@ -209,6 +210,20 @@ func PushProcess(deps PushProcessDeps) worker.Handler {
209210
 		if err := wq.MarkPushEventProcessed(ctx, deps.Pool, event.ID); err != nil {
210211
 			return fmt.Errorf("mark processed: %w", err)
211212
 		}
213
+		if actorID := int64ValueOrZero(event.PusherUserID); actorID != 0 {
214
+			if err := social.Emit(ctx, social.Deps{Pool: deps.Pool, Logger: deps.Logger}, social.EmitParams{
215
+				ActorUserID: actorID,
216
+				Kind:        "push",
217
+				RepoID:      event.RepoID,
218
+				SourceKind:  "repo",
219
+				SourceID:    event.RepoID,
220
+				Public:      repo.Visibility == reposdb.RepoVisibilityPublic,
221
+				Payload:     body,
222
+			}); err != nil && deps.Logger != nil {
223
+				deps.Logger.WarnContext(ctx, "push:process: emit push event",
224
+					"push_event_id", event.ID, "error", err)
225
+			}
226
+		}
212227
 
213228
 		// Wake any size_recalc workers waiting on LISTEN.
214229
 		_ = worker.Notify(ctx, deps.Pool)
internal/worker/types.gomodified
@@ -73,6 +73,12 @@ const (
7373
 	KindNotifyFanout Kind = "notify:fanout"
7474
 )
7575
 
76
+// S42 social feed kinds. trending:compute refreshes the denormalized
77
+// day/week/month Explore rankings.
78
+const (
79
+	KindTrendingCompute Kind = "trending:compute"
80
+)
81
+
7682
 // NotifyChannel is the Postgres LISTEN/NOTIFY channel the pool subscribes
7783
 // to so it wakes up immediately when a job is enqueued, instead of
7884
 // polling. Callers wrapping enqueue in a tx must NOTIFY inside the