aboutsummaryrefslogtreecommitdiffhomepage
path: root/worker/models.go
blob: c60002c629afd55a08df257be5789c0b0ffbccc1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main

import (
	"errors"
	"time"
)

const (
	resultSuccess       = "success"
	resultRuntimeError  = "runtime_error"
	resultTimeout       = "timeout"
	resultInternalError = "internal_error"
)

var (
	errInvalidMaxDuration = errors.New("'max_duration_ms' must be positive")
)

type swiftCompileRequestData struct {
	MaxDurationMilliseconds int    `json:"max_duration_ms"`
	Code                    string `json:"code"`
}

func (req *swiftCompileRequestData) maxDuration() time.Duration {
	return time.Duration(req.MaxDurationMilliseconds) * time.Millisecond
}

func (req *swiftCompileRequestData) validate() error {
	if req.MaxDurationMilliseconds <= 0 {
		return errInvalidMaxDuration
	}
	return nil
}

type swiftCompileResponseData struct {
	Status string `json:"status"`
	Stdout string `json:"stdout"`
	Stderr string `json:"stderr"`
}

type wasmCompileRequestData struct {
	MaxDurationMilliseconds int    `json:"max_duration_ms"`
	Code                    string `json:"code"`
}

type wasmCompileResponseData struct {
	Status string `json:"status"`
	Stdout string `json:"stdout"`
	Stderr string `json:"stderr"`
}

func (req *wasmCompileRequestData) maxDuration() time.Duration {
	return time.Duration(req.MaxDurationMilliseconds) * time.Millisecond
}

func (req *wasmCompileRequestData) validate() error {
	if req.MaxDurationMilliseconds <= 0 {
		return errInvalidMaxDuration
	}
	return nil
}

type testRunRequestData struct {
	MaxDurationMilliseconds int    `json:"max_duration_ms"`
	Code                    string `json:"code"`
	Stdin                   string `json:"stdin"`
}

func (req *testRunRequestData) maxDuration() time.Duration {
	return time.Duration(req.MaxDurationMilliseconds) * time.Millisecond
}

func (req *testRunRequestData) validate() error {
	if req.MaxDurationMilliseconds <= 0 {
		return errInvalidMaxDuration
	}
	return nil
}

type testRunResponseData struct {
	Status string `json:"status"`
	Stdout string `json:"stdout"`
	Stderr string `json:"stderr"`
}