Skip to content

Commit c0325dc

Browse files
committed
Make sure FASTA file is written only after the jobfolder is created for the last time
1 parent d8eb728 commit c0325dc

File tree

2 files changed

+32
-20
lines changed

2 files changed

+32
-20
lines changed

backend/src/backend/jobsystem.go

+23
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,19 @@ func (m *JobRequest) UnmarshalJSON(b []byte) error {
5858
return errors.New("Invalid Job Type")
5959
}
6060

61+
func (m *JobRequest) WriteSupportFiles(base string) error {
62+
switch m.Type {
63+
case JobSearch:
64+
if j, ok := m.Job.(SearchJob); ok {
65+
return j.WriteFasta(filepath.Join(base, "job.fasta"))
66+
}
67+
return errors.New("Invalid Job Type")
68+
case JobIndex:
69+
return nil
70+
}
71+
return nil
72+
}
73+
6174
type Job interface {
6275
Hash() Id
6376
Rank() float64
@@ -176,6 +189,11 @@ func (j *RedisJobSystem) NewJob(request JobRequest, jobsbase string, allowResubm
176189

177190
t := Ticket{id, StatusUnknown}
178191
err = j.Client.Watch(func(tx *redis.Tx) error {
192+
err := request.WriteSupportFiles(workdir)
193+
if err != nil {
194+
return err
195+
}
196+
179197
file, err := os.Create(filepath.Join(workdir, "job.json"))
180198
if err != nil {
181199
return err
@@ -425,6 +443,11 @@ func (j *LocalJobSystem) NewJob(request JobRequest, jobsbase string, allowResubm
425443
}
426444
}
427445

446+
err = request.WriteSupportFiles(workdir)
447+
if err != nil {
448+
return Ticket{id, StatusError}, err
449+
}
450+
428451
file, err := os.Create(filepath.Join(workdir, "job.json"))
429452
if err != nil {
430453
return Ticket{id, StatusError}, err

backend/src/backend/searchjob.go

+9-20
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import (
55
"encoding/base64"
66
"errors"
77
"io/ioutil"
8-
"os"
9-
"path/filepath"
108
"sort"
119
"strings"
1210
)
@@ -44,6 +42,14 @@ func (r SearchJob) Rank() float64 {
4442
return float64(r.Size * max(len(r.Database), 1))
4543
}
4644

45+
func (r SearchJob) WriteFasta(path string) error {
46+
err := ioutil.WriteFile(path, []byte(r.query), 0644)
47+
if err != nil {
48+
return err
49+
}
50+
return nil
51+
}
52+
4753
func isIn(num string, params []string) int {
4854
for i, param := range params {
4955
if num == param {
@@ -75,29 +81,12 @@ func NewSearchJobRequest(query string, dbs []string, validDbs []Params, mode str
7581
ids[i] = item.Display.Path
7682
}
7783

78-
paths := make([]string, len(job.Database))
79-
for i, item := range job.Database {
84+
for _, item := range job.Database {
8085
idx := isIn(item, ids)
8186
if idx == -1 {
8287
return request, errors.New("Selected databases are not valid!")
83-
} else {
84-
paths[i] = validDbs[idx].Display.Path
85-
}
86-
}
87-
88-
id := request.Id
89-
path := filepath.Join(resultPath, string(id))
90-
if _, err := os.Stat(path); os.IsNotExist(err) {
91-
err = os.Mkdir(path, 0755)
92-
if err != nil {
93-
return request, err
9488
}
9589
}
9690

97-
err := ioutil.WriteFile(filepath.Join(path, "job.fasta"), []byte(query), 0644)
98-
if err != nil {
99-
return request, err
100-
}
101-
10291
return request, nil
10392
}

0 commit comments

Comments
 (0)