Skip to content

Commit

Permalink
Make sure FASTA file is written only after the jobfolder is created f…
Browse files Browse the repository at this point in the history
…or the last time
  • Loading branch information
milot-mirdita committed Jan 4, 2019
1 parent d8eb728 commit c0325dc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 20 deletions.
23 changes: 23 additions & 0 deletions backend/src/backend/jobsystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ func (m *JobRequest) UnmarshalJSON(b []byte) error {
return errors.New("Invalid Job Type")
}

func (m *JobRequest) WriteSupportFiles(base string) error {
switch m.Type {
case JobSearch:
if j, ok := m.Job.(SearchJob); ok {
return j.WriteFasta(filepath.Join(base, "job.fasta"))
}
return errors.New("Invalid Job Type")
case JobIndex:
return nil
}
return nil
}

type Job interface {
Hash() Id
Rank() float64
Expand Down Expand Up @@ -176,6 +189,11 @@ func (j *RedisJobSystem) NewJob(request JobRequest, jobsbase string, allowResubm

t := Ticket{id, StatusUnknown}
err = j.Client.Watch(func(tx *redis.Tx) error {
err := request.WriteSupportFiles(workdir)
if err != nil {
return err
}

file, err := os.Create(filepath.Join(workdir, "job.json"))
if err != nil {
return err
Expand Down Expand Up @@ -425,6 +443,11 @@ func (j *LocalJobSystem) NewJob(request JobRequest, jobsbase string, allowResubm
}
}

err = request.WriteSupportFiles(workdir)
if err != nil {
return Ticket{id, StatusError}, err
}

file, err := os.Create(filepath.Join(workdir, "job.json"))
if err != nil {
return Ticket{id, StatusError}, err
Expand Down
29 changes: 9 additions & 20 deletions backend/src/backend/searchjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"encoding/base64"
"errors"
"io/ioutil"
"os"
"path/filepath"
"sort"
"strings"
)
Expand Down Expand Up @@ -44,6 +42,14 @@ func (r SearchJob) Rank() float64 {
return float64(r.Size * max(len(r.Database), 1))
}

func (r SearchJob) WriteFasta(path string) error {
err := ioutil.WriteFile(path, []byte(r.query), 0644)
if err != nil {
return err
}
return nil
}

func isIn(num string, params []string) int {
for i, param := range params {
if num == param {
Expand Down Expand Up @@ -75,29 +81,12 @@ func NewSearchJobRequest(query string, dbs []string, validDbs []Params, mode str
ids[i] = item.Display.Path
}

paths := make([]string, len(job.Database))
for i, item := range job.Database {
for _, item := range job.Database {
idx := isIn(item, ids)
if idx == -1 {
return request, errors.New("Selected databases are not valid!")
} else {
paths[i] = validDbs[idx].Display.Path
}
}

id := request.Id
path := filepath.Join(resultPath, string(id))
if _, err := os.Stat(path); os.IsNotExist(err) {
err = os.Mkdir(path, 0755)
if err != nil {
return request, err
}
}

err := ioutil.WriteFile(filepath.Join(path, "job.fasta"), []byte(query), 0644)
if err != nil {
return request, err
}

return request, nil
}

0 comments on commit c0325dc

Please sign in to comment.