2015-10-21 23:14:02 +00:00
|
|
|
package datastore
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"io"
|
|
|
|
"io/ioutil"
|
|
|
|
|
|
|
|
"github.com/drone/drone/model"
|
|
|
|
"github.com/russross/meddler"
|
|
|
|
)
|
|
|
|
|
2016-03-25 19:54:16 +00:00
|
|
|
func (db *datastore) ReadLog(job *model.Job) (io.ReadCloser, error) {
|
2015-10-21 23:14:02 +00:00
|
|
|
var log = new(model.Log)
|
|
|
|
var err = meddler.QueryRow(db, log, rebind(logQuery), job.ID)
|
|
|
|
var buf = bytes.NewBuffer(log.Data)
|
|
|
|
return ioutil.NopCloser(buf), err
|
|
|
|
}
|
|
|
|
|
2016-03-25 19:54:16 +00:00
|
|
|
func (db *datastore) WriteLog(job *model.Job, r io.Reader) error {
|
2015-10-21 23:14:02 +00:00
|
|
|
var log = new(model.Log)
|
|
|
|
var err = meddler.QueryRow(db, log, rebind(logQuery), job.ID)
|
|
|
|
if err != nil {
|
|
|
|
log = &model.Log{JobID: job.ID}
|
|
|
|
}
|
|
|
|
log.Data, _ = ioutil.ReadAll(r)
|
|
|
|
return meddler.Save(db, logTable, log)
|
|
|
|
}
|
|
|
|
|
|
|
|
const logTable = "logs"
|
|
|
|
|
|
|
|
const logQuery = `
|
|
|
|
SELECT *
|
|
|
|
FROM logs
|
|
|
|
WHERE log_job_id=?
|
|
|
|
LIMIT 1
|
|
|
|
`
|