diff --git a/backend/src/backend/jobsystem.go b/backend/src/backend/jobsystem.go index aae143d..da4c4d9 100644 --- a/backend/src/backend/jobsystem.go +++ b/backend/src/backend/jobsystem.go @@ -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 @@ -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 @@ -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 diff --git a/backend/src/backend/searchjob.go b/backend/src/backend/searchjob.go index 0663ad2..ef4230d 100644 --- a/backend/src/backend/searchjob.go +++ b/backend/src/backend/searchjob.go @@ -5,8 +5,6 @@ import ( "encoding/base64" "errors" "io/ioutil" - "os" - "path/filepath" "sort" "strings" ) @@ -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 { @@ -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 }