Openstatus www.openstatus.dev
6
fork

Configure Feed

Select the types of activity you want to include in your feed.

๐Ÿ› run cli (#1088)

* ๐Ÿ› run cli

* ci: apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>

authored by

Thibault Le Ouay
autofix-ci[bot]
and committed by
GitHub
4c0b22e7 88dea545

+29 -10
+2
apps/checker/handlers/checker.go
··· 88 88 } 89 89 90 90 var called int 91 + 91 92 var result checker.Response 92 93 93 94 op := func() error { ··· 177 178 178 179 result = res 179 180 result.Region = h.Region 181 + result.JobType = "http" 180 182 181 183 // it's in error if not successful 182 184 if isSuccessfull {
+3
apps/checker/handlers/tcp.go
··· 17 17 type TCPResponse struct { 18 18 Region string `json:"region"` 19 19 ErrorMessage string `json:"errorMessage"` 20 + JobType string `json:"jobType"` 20 21 RequestId int64 `json:"requestId,omitempty"` 21 22 WorkspaceID int64 `json:"workspaceId"` 22 23 MonitorID int64 `json:"monitorId"` ··· 95 96 } 96 97 97 98 var called int 99 + 98 100 var response TCPResponse 99 101 100 102 op := func() error { ··· 268 270 }, 269 271 Latency: res.TCPDone - res.TCPStart, 270 272 Region: h.Region, 273 + JobType: "tcp", 271 274 } 272 275 273 276 timingAsString, err := json.Marshal(res)
+3
apps/checker/http.go
··· 36 36 Body string `json:"body,omitempty"` 37 37 Error string `json:"error,omitempty"` 38 38 Region string `json:"region"` 39 + JobType string `json:"jobType"` 39 40 Latency int64 `json:"latency"` 40 41 Timestamp int64 `json:"timestamp"` 41 42 Status int `json:"status,omitempty"` ··· 80 81 if inputData.Method != http.MethodGet { 81 82 head := req.Header 82 83 _, ok := head["Content-Type"] 84 + 83 85 if !ok { 84 86 // by default we set the content type to application/json if it's a POST request 85 87 req.Header.Set("Content-Type", "application/json") ··· 127 129 128 130 return Response{}, fmt.Errorf("error with monitorURL %s: %w", inputData.URL, err) 129 131 } 132 + 130 133 defer response.Body.Close() 131 134 132 135 body, err := io.ReadAll(response.Body)
+5 -2
apps/server/src/checker/index.ts
··· 200 200 .from(workspace) 201 201 .where(eq(workspace.id, monitor.workspaceId)) 202 202 .get(); 203 - if (currentWorkspace?.plan !== "free") { 203 + if ( 204 + !!currentWorkspace?.plan && 205 + currentWorkspace?.plan !== "free" 206 + ) { 204 207 await triggerScreenshot({ 205 208 data: { 206 209 url: monitor.url, ··· 302 305 .where(eq(workspace.id, monitor.workspaceId)) 303 306 .get(); 304 307 305 - if (currentWorkspace?.plan !== "free") { 308 + if (!!currentWorkspace?.plan && currentWorkspace?.plan !== "free") { 306 309 await triggerScreenshot({ 307 310 data: { 308 311 url: monitor.url,
+9 -8
apps/server/src/v1/monitors/run/post.ts
··· 12 12 import type { monitorsApi } from ".."; 13 13 import { env } from "../../../env"; 14 14 import { openApiErrorResponses } from "../../../libs/errors/openapi-error-responses"; 15 - import { HTTPTriggerResult, ParamsSchema, TCPTriggerResult } from "../schema"; 15 + import { 16 + HTTPTriggerResult, 17 + ParamsSchema, 18 + TCPTriggerResult, 19 + TriggerResult, 20 + } from "../schema"; 16 21 17 22 const triggerMonitor = createRoute({ 18 23 method: "post", ··· 193 198 // console.log(result); 194 199 195 200 const bodies = await Promise.all(result.map((r) => r.json())); 196 - let data = null; 197 - if (row.jobType === "http") { 198 - data = z.array(HTTPTriggerResult).safeParse(bodies); 199 - } 200 - if (row.jobType === "tcp") { 201 - data = z.array(TCPTriggerResult).safeParse(bodies); 202 - } 201 + // let data = null; 202 + 203 + const data = z.array(TriggerResult).safeParse(bodies); 203 204 204 205 if (!data) { 205 206 throw new HTTPException(400, { message: "Something went wrong" });
+7
apps/server/src/v1/monitors/schema.ts
··· 234 234 }); 235 235 236 236 export const HTTPTriggerResult = z.object({ 237 + jobType: z.literal("http"), 237 238 status: z.number(), 238 239 latency: z.number(), 239 240 region: z.enum(flyRegions), ··· 249 250 }); 250 251 251 252 export const TCPTriggerResult = z.object({ 253 + jobType: z.literal("tcp"), 252 254 latency: z.number(), 253 255 region: z.enum(flyRegions), 254 256 timestamp: z.number(), ··· 256 258 error: z.number().optional().nullable(), 257 259 errorMessage: z.string().optional().nullable(), 258 260 }); 261 + 262 + export const TriggerResult = z.discriminatedUnion("jobType", [ 263 + HTTPTriggerResult, 264 + TCPTriggerResult, 265 + ]); 259 266 260 267 export const ResultRun = z.object({ 261 268 latency: z.number().int(), // in ms