Skip to content

Commit

Permalink
getting started on the new engine session queuing
Browse files Browse the repository at this point in the history
  • Loading branch information
caffix committed Feb 23, 2025
1 parent eeaf0e2 commit 982122d
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions engine/sessions/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,20 @@ func CreateSession(cfg *config.Config) (et.Session, error) {
}
s.log = slog.New(slog.NewJSONHandler(s.ps, nil)).With("session", s.id)

if err := s.setupDB(); err != nil {
err := s.setupDB()
if err != nil {
return nil, err
}

s.tmpdir, err = s.createTemporaryDir()
if err != nil {
return nil, err
}

c, dir, err := s.createFileCacheRepo()
c, err := s.createFileRepo("cache.sqlite")
if err != nil {
return nil, err
}
s.tmpdir = dir

s.c, err = cache.New(c, s.db, time.Minute)
if err != nil || s.c == nil {
Expand Down Expand Up @@ -194,16 +199,25 @@ func (s *Session) selectDBMS() error {
return nil
}

func (s *Session) createFileCacheRepo() (repository.Repository, string, error) {
dir, err := os.MkdirTemp("", s.ID().String())
if err != nil {
return nil, "", errors.New("failed to create the temp dir")
func (s *Session) createTemporaryDir() (string, error) {
outdir := config.OutputDirectory()
if outdir == "" {
return "", errors.New("failed to obtain the output directory")
}

c, err := assetdb.New(sqlrepo.SQLite, filepath.Join(dir, "cache.sqlite"))
dir, err := os.MkdirTemp(outdir, "session-"+s.ID().String())
if err != nil {
return nil, "", fmt.Errorf("failed to create the cache db: %s", err.Error())
return "", errors.New("failed to create the temp dir")
}

return c, dir, nil
return dir, nil
}

func (s *Session) createFileRepo(fname string) (repository.Repository, error) {
c, err := assetdb.New(sqlrepo.SQLite, filepath.Join(s.TmpDir(), fname))

if err != nil {
return nil, fmt.Errorf("failed to create the db: %s", err.Error())
}
return c, nil
}

0 comments on commit 982122d

Please sign in to comment.