-
Notifications
You must be signed in to change notification settings - Fork 40
Scheduler service #977
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Scheduler service #977
Conversation
0da74a4 to
007905d
Compare
b9ba9ff to
3020a4f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR implements a scheduler service to enable scheduling of news articles for future publishing. It introduces a new Go-based microservice that handles task scheduling and execution, integrates it with the existing SvelteKit application, and updates the authentication flow to support token refresh.
Key Changes
- New Go scheduler microservice with REST API for scheduling and executing tasks
- Enhanced JWT authentication flow with refresh token support
- Article creation form extended with publish date scheduling
- Frontend display of scheduled articles for authorized users
Reviewed changes
Copilot reviewed 20 out of 21 changed files in this pull request and generated 32 comments.
Show a summary per file
| File | Description |
|---|---|
| scheduler-service/main.go | Entry point for scheduler service, handles initialization and startup |
| scheduler-service/taskHandler.go | Task execution logic including scheduling and HTTP callbacks |
| scheduler-service/requestHandler.go | API endpoints for creating and querying scheduled tasks |
| scheduler-service/authMiddleware.go | JWT authentication middleware with JWKS caching |
| scheduler-service/rateLimitMiddleware.go | IP-based rate limiting for API requests |
| scheduler-service/databaseHandler.go | PostgreSQL database connection setup |
| scheduler-service/go.mod | Go module dependencies (contains invalid Go version) |
| scheduler-service/.env | Environment configuration (should not be committed) |
| src/lib/news/schema.ts | Added publishTime field to article schema |
| src/lib/news/server/actions.ts | Updated article creation to support scheduling via external service |
| src/lib/news/server/notifications.ts | Extracted notification logic for reusability |
| src/routes/(app)/api/schedule/news/+server.ts | Callback endpoint for scheduler to create articles |
| src/routes/(app)/news/ArticleForm.svelte | Added date input for scheduling articles |
| src/routes/(app)/news/+page.svelte | Display list of scheduled articles |
| src/routes/(app)/news/+page.server.ts | Fetch scheduled tasks from scheduler service |
| src/lib/server/getDecryptedJWT.ts | Utility to decrypt JWT from request cookies |
| src/hooks.server.ts | Enhanced JWT callback with refresh token support |
| src/translations/en.json | English translations for scheduling features |
| src/translations/sv.json | Swedish translations for scheduling features |
| .env | Added scheduler endpoint and password configuration |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| type ScheduledTaskRaw = { | ||
| ID: string; | ||
| RunTimestamp: string; | ||
| Body: string; | ||
| }; | ||
|
|
||
| type ScheduledTaskParsed = { | ||
| ID: string; | ||
| RunTimestamp: string; | ||
| Body: NewsArticleData; | ||
| }; | ||
|
|
||
| type NewsArticleData = { | ||
| author: { | ||
| connect: | ||
| | { | ||
| id: string; | ||
| } | ||
| | undefined; | ||
| create: | ||
| | { | ||
| member: { | ||
| connect: { | ||
| studentId: string | undefined; | ||
| }; | ||
| }; | ||
| mandate: | ||
| | { | ||
| connect: { | ||
| member: { | ||
| studentId: string | undefined; | ||
| }; | ||
| id: string; | ||
| }; | ||
| } | ||
| | undefined; | ||
| customAuthor: | ||
| | { | ||
| connect: { | ||
| id: string; | ||
| }; | ||
| } | ||
| | undefined; | ||
| } | ||
| | undefined; | ||
| }; | ||
| tags: { | ||
| connect: Array<{ | ||
| id: string; | ||
| }>; | ||
| }; | ||
| publishedAt: Date; | ||
| imageUrl?: string | null | undefined; | ||
| imageUrls?: string[] | undefined; | ||
| youtubeUrl?: string | null | undefined; | ||
| slug: string; | ||
| headerSv: string; | ||
| headerEn: string | null; | ||
| bodySv: string; | ||
| bodyEn: string | null; | ||
| }; |
Copilot
AI
Nov 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The NewsArticleData type is duplicated and defined inline. This complex type definition (lines 77-125) should be extracted to a shared types file or imported from the schema definition to maintain a single source of truth and avoid type drift between the scheduler request and the article creation.
| @@ -0,0 +1,6 @@ | |||
| import { env } from "$env/dynamic/private"; | |||
| import { getToken, type JWT } from "@auth/core/jwt"; | |||
|
|
|||
Copilot
AI
Nov 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This utility function lacks documentation explaining its purpose, when it should be used, and what it returns. Add a JSDoc comment describing that it decrypts and returns the JWT from the request cookie, and explain when it might return null (e.g., user not authenticated).
| /** | |
| * Decrypts and returns the JWT from the request cookie. | |
| * | |
| * Use this function when you need to access the authenticated user's JWT from a request. | |
| * Returns the JWT object if the user is authenticated, or `null` if the user is not authenticated | |
| * or if the JWT is missing or invalid. | |
| * | |
| * @param req - The incoming HTTP request containing the JWT cookie. | |
| * @returns The decrypted JWT object, or `null` if not authenticated. | |
| */ |
| <FormDateInput | ||
| {superform} | ||
| field="publishTime" | ||
| label="Schemalägg publicering" |
Copilot
AI
Nov 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hard-coded Swedish text "Schemalägg publicering" should use the translation system instead. This should be replaced with a translation key like {m.news_schedulePublishing()} to support multiple languages consistently with the rest of the application.
| label="Schemalägg publicering" | |
| label={m.news_schedulePublishing()} |
- Added `publishTime` field to article schema and form for scheduling article publication - Implemented backend logic to send data to the scheduler service for later publishing - Created API endpoint `/api/schedule/news` to handle scheduled article creation and notifications
57667bf to
8e4fe3d
Compare
|
This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 14 days. |
Implements #928
Draft for now - not done. Will update with more info later.