Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ const darkCodeTheme = require('prism-react-renderer/themes/dracula');
({
docs: {
sidebarPath: require.resolve('./sidebars.js'),
editUrl: 'https://github.com/makeopensource/leviathan/edit/main/website/',
editUrl: 'https://github.com/makeopensource/leviathan/edit/main/',
},
blog: {
showReadingTime: true,
editUrl:
'https://github.com/makeopensource/leviathan/edit/main/website/blog/',
'https://github.com/makeopensource/leviathan/edit/main/blog/',
},
theme: {
customCss: require.resolve('./src/css/custom.css'),
Expand Down
25 changes: 7 additions & 18 deletions src/common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package common

import (
"archive/tar"
"bufio"
"bytes"
"compress/gzip"
"encoding/json"
"errors"
"fmt"
v1 "github.com/makeopensource/leviathan/generated/types/v1"
"github.com/rs/zerolog/log"
Expand Down Expand Up @@ -260,27 +260,16 @@ func IsValidJSON(s string) bool {
return json.Unmarshal([]byte(s), &js) == nil
}

// ParseCombinedID decode combined id which should contain the machine id and container id
func ParseCombinedID(combinedId string) (string, string, error) {
machineId, containerId, err := DecodeID(combinedId)
func ReadBufLogfile(logPath string) error {
file, err := os.Open(logPath)
if err != nil {
log.Error().Err(err).Str("ID", combinedId).Msg("Could not decode ID")
return "", "", err
return err
}

return containerId, machineId, nil
}

func EncodeID(id1 string, id2 string) string {
return id1 + "#" + id2
}
reader := bufio.NewScanner(file)
reader.Scan()

func DecodeID(combinedId string) (string, string, error) {
strs := strings.Split(combinedId, "#")
if len(strs) != 2 {
return "", "", errors.New("could not decode ID")
}
return strs[0], strs[1], nil
return nil
}

func ReadLogFile(logPath string) string {
Expand Down
4 changes: 2 additions & 2 deletions src/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ go 1.24

require (
connectrpc.com/connect v1.18.1
github.com/docker/cli v28.0.1+incompatible
github.com/docker/docker v28.0.1+incompatible
github.com/docker/cli v28.0.2+incompatible
github.com/docker/docker v28.0.2+incompatible
github.com/go-viper/mapstructure/v2 v2.2.1
github.com/google/uuid v1.6.0
github.com/joho/godotenv v1.5.1
Expand Down
4 changes: 4 additions & 0 deletions src/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5Qvfr
github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
github.com/docker/cli v28.0.1+incompatible h1:g0h5NQNda3/CxIsaZfH4Tyf6vpxFth7PYl3hgCPOKzs=
github.com/docker/cli v28.0.1+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
github.com/docker/cli v28.0.2+incompatible h1:cRPZ77FK3/IXTAIQQj1vmhlxiLS5m+MIUDwS6f57lrE=
github.com/docker/cli v28.0.2+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
github.com/docker/docker v28.0.1+incompatible h1:FCHjSRdXhNRFjlHMTv4jUNlIBbTeRjrWfeFuJp7jpo0=
github.com/docker/docker v28.0.1+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/docker v28.0.2+incompatible h1:9BILleFwug5FSSqWBgVevgL3ewDJfWWWyZVqlDMttE8=
github.com/docker/docker v28.0.2+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj1Br63c=
github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc=
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
Expand Down
29 changes: 20 additions & 9 deletions src/models/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

type JobStatus string

// Done indicate the job has been tried by the queue, and processed.
// Done indicate the job has been tried by the queue and processed.
// i.e: the JobStatus is either Failed, Complete, Canceled
func (js JobStatus) Done() bool {
if js == Failed || js == Complete || js == Canceled {
Expand All @@ -19,14 +19,23 @@ func (js JobStatus) Done() bool {
return false
}

// job status enum
// go way of doing enums
const (
Queued JobStatus = "queued"
// Queued -> job was sent to the job channel waiting to be picked by a worker
Queued JobStatus = "queued"
// Preparing -> job is picked up by a worker
// and the required setup is being done.
Preparing JobStatus = "preparing"
Running JobStatus = "running"
Complete JobStatus = "complete"
Failed JobStatus = "failed"
Canceled JobStatus = "canceled"
// Running leviathan has successfully started the grading container
// and is waiting for it to end
Running JobStatus = "running"
// Complete -> indicates job is complete and
// leviathan was able to parse the log line correctly
Complete JobStatus = "complete"
// Failed -> job failed for one of the variety of reasons
Failed JobStatus = "failed"
// Canceled -> job was cancelled by the user
Canceled JobStatus = "canceled"
)

// general resource units for docker
Expand All @@ -45,8 +54,10 @@ type Job struct {
JobEntryCmd string
Status JobStatus
StatusMessage string
LabData Lab `gorm:"embedded;embeddedPrefix:lab_"`
JobLimits MachineLimits `gorm:"embedded;embeddedPrefix:machine_limit_"`
// to store if an error occurred, otherwise empty,
Error string
LabData Lab `gorm:"embedded;embeddedPrefix:lab_"`
JobLimits MachineLimits `gorm:"embedded;embeddedPrefix:machine_limit_"`
// OutputLogFilePath text file contain the container std out
OutputLogFilePath string
// TmpJobFolderPath holds the path to the tmp dir all files related to the job except the final output
Expand Down
12 changes: 0 additions & 12 deletions src/service/docker/docker_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,6 @@ func (c *DkClient) ListContainers(machineId string) ([]*dktypes.ContainerMetaDat
log.Debug().Msgf("Docker images listed: %d", len(containerInfos))

var containerInfoList []*dktypes.ContainerMetaData
for _, item := range containerInfos {
info := dktypes.ContainerMetaData{
Id: common.EncodeID(machineId, item.ID),
ContainerNames: item.Names,
Image: item.Image,
Status: item.Status,
State: item.State,
}

containerInfoList = append(containerInfoList, &info)
}

return containerInfoList, nil
}

Expand Down
Loading