Fix name conflict in Waspleau (#830)

Co-authored-by: shayneczyzewski <shayne.czyzewski@gmail.com>
This commit is contained in:
Filip Sodić 2022-11-24 15:19:22 +01:00 committed by GitHub
parent 24fb75ffd0
commit adc1e1a84b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 37 additions and 16 deletions

View File

@ -1,6 +1,6 @@
app waspleau {
wasp: {
version: "^0.6.0"
version: "^0.7.0"
},
title: "Waspleau",
@ -24,7 +24,7 @@ job github {
schedule: {
cron: "*/10 * * * *"
},
entities: [Metric]
entities: [Datum]
}
job loadTime {
@ -39,10 +39,10 @@ job loadTime {
"name": "wasp-lang.dev Load Time"
} json=}
},
entities: [Metric]
entities: [Datum]
}
entity Metric {=psl
entity Datum {=psl
id Int @id @default(autoincrement())
name String @unique
value String
@ -56,5 +56,5 @@ page MainPage {
query dashboard {
fn: import { refreshDashboardData } from "@server/dashboard.js",
entities: [Metric]
entities: [Datum]
}

View File

@ -0,0 +1,21 @@
/*
Warnings:
- You are about to drop the `Metric` table. If the table is not empty, all the data it contains will be lost.
*/
-- DropTable
DROP TABLE "Metric";
-- CreateTable
CREATE TABLE "Datum" (
"id" SERIAL NOT NULL,
"name" TEXT NOT NULL,
"value" TEXT NOT NULL,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "Datum_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE UNIQUE INDEX "Datum_name_key" ON "Datum"("name");

View File

@ -1,5 +1,5 @@
export const refreshDashboardData = async (_args, context) => {
return context.entities.Metric.findMany({
return context.entities.Datum.findMany({
orderBy: [
{
name: 'asc',

View File

@ -1,19 +1,19 @@
import axios from 'axios'
import { upsertMetric } from './utils.js'
import { upsertData } from './utils.js'
export async function workerFunction(args, context) {
console.log('github.js workerFunction', args, context)
const response = await axios.get('https://api.github.com/repos/wasp-lang/wasp')
const metrics = [
const data = [
{ name: 'Wasp GitHub Stars', value: response.data.stargazers_count },
{ name: 'Wasp GitHub Language', value: response.data.language },
{ name: 'Wasp GitHub Forks', value: response.data.forks },
{ name: 'Wasp GitHub Open Issues', value: response.data.open_issues },
]
await Promise.all(metrics.map(upsertMetric(context)))
await Promise.all(data.map(upsertData(context)))
return metrics
return data
}

View File

@ -1,5 +1,5 @@
import axios from 'axios'
import { upsertMetric } from './utils.js'
import { upsertData } from './utils.js'
export async function workerFunction(args, context) {
console.log('loadTime.js workerFunction', args, context)
@ -8,9 +8,9 @@ export async function workerFunction(args, context) {
await axios.get(args.url)
const end = Date.now()
const metrics = [{ name: args.name, value: `${end - start}ms` }]
const data = [{ name: args.name, value: `${end - start}ms` }]
await Promise.all(metrics.map(upsertMetric(context)))
await Promise.all(data.map(upsertData(context)))
return metrics
return data
}

View File

@ -1,6 +1,6 @@
export function upsertMetric(context) {
export function upsertData(context) {
return ({ name, value } = {}) => {
return context.entities.Metric.upsert({
return context.entities.Datum.upsert({
where: { name },
update: { name, value: String(value) },
create: { name, value: String(value) }