aboutsummaryrefslogtreecommitdiffhomepage
path: root/worker/models.go
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2024-08-02 19:16:58 +0900
committernsfisis <nsfisis@gmail.com>2024-08-03 18:56:00 +0900
commitf70d6eed9f2c519aed030c9dbda99ed0435991a0 (patch)
tree2c4e95392c88fcdbccafe62e42b651f4fbde0491 /worker/models.go
parentdb06c9332776b41b3fef537f9e6d76d38f0463b3 (diff)
downloadiosdc-japan-2024-albatross-f70d6eed9f2c519aed030c9dbda99ed0435991a0.tar.gz
iosdc-japan-2024-albatross-f70d6eed9f2c519aed030c9dbda99ed0435991a0.tar.zst
iosdc-japan-2024-albatross-f70d6eed9f2c519aed030c9dbda99ed0435991a0.zip
feat: implement worker
Diffstat (limited to 'worker/models.go')
-rw-r--r--worker/models.go84
1 files changed, 84 insertions, 0 deletions
diff --git a/worker/models.go b/worker/models.go
new file mode 100644
index 0000000..b838fe0
--- /dev/null
+++ b/worker/models.go
@@ -0,0 +1,84 @@
+package main
+
+import (
+ "errors"
+ "time"
+)
+
+const (
+ resultSuccess = "success"
+ resultFailure = "failure"
+ 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 {
+ Result string `json:"result"`
+ Stdout string `json:"stdout"`
+ Stderr string `json:"stderr"`
+}
+
+type wasmCompileRequestData struct {
+ MaxDurationMilliseconds int `json:"max_duration_ms"`
+ Code string `json:"code"`
+}
+
+type wasmCompileResponseData struct {
+ Result string `json:"result"`
+ 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 {
+ Result string `json:"result"`
+ Stdout string `json:"stdout"`
+ Stderr string `json:"stderr"`
+}