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{
129
 			BaseURL:        cfg.Auth.BaseURL,
129
 			BaseURL:        cfg.Auth.BaseURL,
130
 			UnsubscribeKey: notifUnsubscribeKey(cfg, logger),
130
 			UnsubscribeKey: notifUnsubscribeKey(cfg, logger),
131
 		}))
131
 		}))
132
+		p.Register(worker.KindTrendingCompute, jobs.TrendingCompute(jobs.TrendingComputeDeps{
133
+			Pool: pool, Logger: logger,
134
+		}))
132
 
135
 
133
 		// Webhook delivery (S33). The fan-out drains domain_events
136
 		// Webhook delivery (S33). The fan-out drains domain_events
134
 		// past its own cursor; deliver runs per-row HTTP POSTs;
137
 		// past its own cursor; deliver runs per-row HTTP POSTs;
internal/repos/create.gomodified
@@ -21,6 +21,7 @@ import (
21
 	"github.com/tenseleyFlow/shithub/internal/infra/storage"
21
 	"github.com/tenseleyFlow/shithub/internal/infra/storage"
22
 	"github.com/tenseleyFlow/shithub/internal/issues"
22
 	"github.com/tenseleyFlow/shithub/internal/issues"
23
 	issuesdb "github.com/tenseleyFlow/shithub/internal/issues/sqlc"
23
 	issuesdb "github.com/tenseleyFlow/shithub/internal/issues/sqlc"
24
+	"github.com/tenseleyFlow/shithub/internal/notif"
24
 	repogit "github.com/tenseleyFlow/shithub/internal/repos/git"
25
 	repogit "github.com/tenseleyFlow/shithub/internal/repos/git"
25
 	reposdb "github.com/tenseleyFlow/shithub/internal/repos/sqlc"
26
 	reposdb "github.com/tenseleyFlow/shithub/internal/repos/sqlc"
26
 	"github.com/tenseleyFlow/shithub/internal/repos/templates"
27
 	"github.com/tenseleyFlow/shithub/internal/repos/templates"
@@ -269,6 +270,20 @@ func Create(ctx context.Context, deps Deps, p Params) (Result, error) {
269
 	}
270
 	}
270
 	committed = true
271
 	committed = true
271
 
272
 
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
+
272
 	if err := deps.Audit.Record(ctx, deps.Pool, p.ActorUserID,
287
 	if err := deps.Audit.Record(ctx, deps.Pool, p.ActorUserID,
273
 		audit.ActionRepoCreated, audit.TargetRepo, row.ID, map[string]any{
288
 		audit.ActionRepoCreated, audit.TargetRepo, row.ID, map[string]any{
274
 			"name":       p.Name,
289
 			"name":       p.Name,
internal/worker/jobs/push_process.gomodified
@@ -25,6 +25,7 @@ import (
25
 	pullsdb "github.com/tenseleyFlow/shithub/internal/pulls/sqlc"
25
 	pullsdb "github.com/tenseleyFlow/shithub/internal/pulls/sqlc"
26
 	gitops "github.com/tenseleyFlow/shithub/internal/repos/git"
26
 	gitops "github.com/tenseleyFlow/shithub/internal/repos/git"
27
 	reposdb "github.com/tenseleyFlow/shithub/internal/repos/sqlc"
27
 	reposdb "github.com/tenseleyFlow/shithub/internal/repos/sqlc"
28
+	"github.com/tenseleyFlow/shithub/internal/social"
28
 	usersdb "github.com/tenseleyFlow/shithub/internal/users/sqlc"
29
 	usersdb "github.com/tenseleyFlow/shithub/internal/users/sqlc"
29
 	"github.com/tenseleyFlow/shithub/internal/worker"
30
 	"github.com/tenseleyFlow/shithub/internal/worker"
30
 	workerdb "github.com/tenseleyFlow/shithub/internal/worker/sqlc"
31
 	workerdb "github.com/tenseleyFlow/shithub/internal/worker/sqlc"
@@ -209,6 +210,20 @@ func PushProcess(deps PushProcessDeps) worker.Handler {
209
 		if err := wq.MarkPushEventProcessed(ctx, deps.Pool, event.ID); err != nil {
210
 		if err := wq.MarkPushEventProcessed(ctx, deps.Pool, event.ID); err != nil {
210
 			return fmt.Errorf("mark processed: %w", err)
211
 			return fmt.Errorf("mark processed: %w", err)
211
 		}
212
 		}
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
+		}
212
 
227
 
213
 		// Wake any size_recalc workers waiting on LISTEN.
228
 		// Wake any size_recalc workers waiting on LISTEN.
214
 		_ = worker.Notify(ctx, deps.Pool)
229
 		_ = worker.Notify(ctx, deps.Pool)
internal/worker/types.gomodified
@@ -73,6 +73,12 @@ const (
73
 	KindNotifyFanout Kind = "notify:fanout"
73
 	KindNotifyFanout Kind = "notify:fanout"
74
 )
74
 )
75
 
75
 
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
+
76
 // NotifyChannel is the Postgres LISTEN/NOTIFY channel the pool subscribes
82
 // NotifyChannel is the Postgres LISTEN/NOTIFY channel the pool subscribes
77
 // to so it wakes up immediately when a job is enqueued, instead of
83
 // to so it wakes up immediately when a job is enqueued, instead of
78
 // polling. Callers wrapping enqueue in a tx must NOTIFY inside the
84
 // polling. Callers wrapping enqueue in a tx must NOTIFY inside the