diff options
| author | nsfisis <nsfisis@gmail.com> | 2025-09-05 22:03:54 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2025-09-05 22:04:06 +0900 |
| commit | bd2ebe9396475632908b23d8263be70166197dc2 (patch) | |
| tree | 21d2ad6f4e106aaa881d66544c27ccee2a96b970 /worker/swift/models.go | |
| parent | 3022b45715b9aabb6f54e5e19429c6b06abc1afd (diff) | |
| download | phperkaigi-2026-albatross-bd2ebe9396475632908b23d8263be70166197dc2.tar.gz phperkaigi-2026-albatross-bd2ebe9396475632908b23d8263be70166197dc2.tar.zst phperkaigi-2026-albatross-bd2ebe9396475632908b23d8263be70166197dc2.zip | |
feat(worker-swift): compile and run in one request
Diffstat (limited to 'worker/swift/models.go')
| -rw-r--r-- | worker/swift/models.go | 56 |
1 files changed, 8 insertions, 48 deletions
diff --git a/worker/swift/models.go b/worker/swift/models.go index 4a318d0..f00265e 100644 --- a/worker/swift/models.go +++ b/worker/swift/models.go @@ -17,70 +17,30 @@ var ( errInvalidMaxDuration = errors.New("'max_duration_ms' must be positive") ) -type swiftCompileRequestData struct { - MaxDurationMilliseconds int `json:"max_duration_ms"` +type execRequestData struct { Code string `json:"code"` CodeHash string `json:"code_hash"` + Stdin string `json:"stdin"` + MaxDurationMilliseconds int `json:"max_duration_ms"` } -func (req *swiftCompileRequestData) maxDuration() time.Duration { +func (req *execRequestData) maxDuration() time.Duration { return time.Duration(req.MaxDurationMilliseconds) * time.Millisecond } -func (req *swiftCompileRequestData) validate() error { +func (req *execRequestData) validate() error { if req.MaxDurationMilliseconds <= 0 { return errInvalidMaxDuration } return nil } -type swiftCompileResponseData struct { +type execResponseData struct { Status string `json:"status"` Stdout string `json:"stdout"` Stderr string `json:"stderr"` } -type wasmCompileRequestData struct { - MaxDurationMilliseconds int `json:"max_duration_ms"` - CodeHash string `json:"code_hash"` -} - -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"` - CodeHash string `json:"code_hash"` - 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"` +func (res *execResponseData) success() bool { + return res.Status == resultSuccess } |
