Skip to content

Conversation

@Fiery-132
Copy link
Contributor

Implements #928

Draft for now - not done. Will update with more info later.

@github-project-automation github-project-automation bot moved this to 🆕 New in CPU Nov 12, 2025
@Fiery-132 Fiery-132 moved this from 🆕 New to 🏗 In Progress in CPU Nov 12, 2025
@Fiery-132 Fiery-132 linked an issue Nov 12, 2025 that may be closed by this pull request
@Fiery-132 Fiery-132 force-pushed the scheduler branch 3 times, most recently from 0da74a4 to 007905d Compare November 15, 2025 00:54
@Isak-Kallini Isak-Kallini moved this from 🏗 In Progress to 🆕 New in CPU Nov 24, 2025
@Fiery-132 Fiery-132 linked an issue Nov 24, 2025 that may be closed by this pull request
Copy link

Copilot AI left a 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.

Comment on lines +65 to +136
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;
};
Copy link

Copilot AI Nov 25, 2025

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.

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,6 @@
import { env } from "$env/dynamic/private";
import { getToken, type JWT } from "@auth/core/jwt";

Copy link

Copilot AI Nov 25, 2025

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).

Suggested change
/**
* 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.
*/

Copilot uses AI. Check for mistakes.
<FormDateInput
{superform}
field="publishTime"
label="Schemalägg publicering"
Copy link

Copilot AI Nov 25, 2025

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.

Suggested change
label="Schemalägg publicering"
label={m.news_schedulePublishing()}

Copilot uses AI. Check for mistakes.
- 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
@Fiery-132 Fiery-132 force-pushed the scheduler branch 2 times, most recently from 57667bf to 8e4fe3d Compare December 17, 2025 09:42
@github-actions
Copy link

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.

@github-actions github-actions bot added the stale Has not been updated for 30 days label Jan 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale Has not been updated for 30 days

Projects

Status: 🆕 New

Development

Successfully merging this pull request may close these issues.

Create a scheduling service Implement handling of refresh tokens

1 participant