Skip to content
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

140 make matching algorithm run at end of application period #163

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .env.local.template
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ AUTH0_CLIENT_SECRET=#client secret
AUTH0_ISSUER=#issuer base url, example: example.us.auth0.com

AWS_SECRET_ACCESS_KEY=#aws secret access key
AWS_ACCESS_KEY_ID=#aws access key id
AWS_ACCESS_KEY_ID=#aws access key id

CRON_SECRET=#secret for vercel cron job access
10 changes: 10 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
sanic = "24.6.0"

[requires]
python_version = "3.12"
8 changes: 8 additions & 0 deletions app/api/index.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from sanic import Sanic
from sanic.response import json
app = Sanic()


@app.route('/algorithm')
async def index(request, path=""):
return json({'hello': "world"})
12 changes: 12 additions & 0 deletions pages/api/cron.js
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ikke typescript?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tok utgangspunkt i en fil jeg fant i noen docs, men kan skrive over til typescript, ja.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default function handler(req, res) {
if (req.headers.get('Authorization') !== `Bearer ${process.env.CRON_SECRET}`) {
return res.status(401).end('Unauthorized');
}

// TODO Check for correct time and run algorithm.
res.status(200).end('Hello Cron!');

const spawn = require("child_process").spawn;

const algorithmProcess = spawn('cd algorithm', ["path/to/script.py", arg1, arg2,], { cwd: "./algorithm/ " });
}
17 changes: 17 additions & 0 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,26 @@ import Button from "../components/Button";
import FestivitiesIllustration from "../components/icons/illustrations/FestivitiesIllustration";
import AuthenticationIllustration from "../components/icons/illustrations/AuthenticationIllustration";
import { signIn, useSession } from "next-auth/react";
import { useEffect, useState } from "react";

const Home = () => {
const { data: session } = useSession();
const handleLogin = () => signIn("auth0");

const [testD, setTestD] = useState<String>("Her står ting");


useEffect(() => {
const testFetch = async () => {
const testVar = await fetch("/api/index.py")
const testData = await testVar.json()

console.log(testData)
setTestD(String(testData))
}
testFetch()
})

if (!session) {
return (
<div className="flex flex-col items-center justify-center h-full gap-5 px-5">
Expand All @@ -22,13 +37,15 @@ const Home = () => {
);
}


return (
<section className="flex items-center justify-center h-full bg-white dark:bg-gray-900">
<div className="grid max-w-screen-xl px-4 py-8 mx-auto lg:gap-8 xl:gap-0 lg:py-16 lg:grid-cols-12">
<div className="mr-auto place-self-center lg:col-span-7">
<h1 className="max-w-2xl mb-4 text-4xl font-bold leading-none tracking-tight md:text-5xl xl:text-6xl dark:text-white">
opptak.online
</h1>
<p>{testD}</p>
<p className="max-w-2xl mb-6 font-light text-gray-500 lg:mb-8 md:text-lg lg:text-xl dark:text-gray-400">
Her skal det stå masse kult om komitéopptak og sånn og om at man må
bli med i komité og at dette er det bra opptakssystem og sånn.
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sanic==24.6.0
8 changes: 8 additions & 0 deletions vercel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"crons": [
{
"path": "/api/cron",
"schedule": "26 16 * * *"
}
]
}