Skip to content

Commit

Permalink
api/worker: capture ffmpeg error and fail job.
Browse files Browse the repository at this point in the history
web: Update jobs/machines/presets table UI fixes.
  • Loading branch information
alfg committed Nov 28, 2019
1 parent ddfd487 commit c21c8a5
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 6 deletions.
18 changes: 15 additions & 3 deletions api/encoder/ffmpeg.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package encoder

import (
"bufio"
"bytes"
"encoding/json"
"fmt"
"io"
"os/exec"
"strconv"
Expand Down Expand Up @@ -42,10 +44,10 @@ type ffmpegOptions struct {
}

// Run runs the ffmpeg encoder with options.
func (f *FFmpeg) Run(input string, output string, data string) {
func (f *FFmpeg) Run(input string, output string, data string) error {
args := []string{
"-hide_banner",
"-v", "0",
"-loglevel", "error", // Set loglevel to fail job on errors.
"-progress", "pipe:1",
"-i", input,
}
Expand All @@ -66,6 +68,10 @@ func (f *FFmpeg) Run(input string, output string, data string) {
log.Info("running FFmpeg with options: ", args)
cmd := exec.Command(ffmpegCmd, args...)
stdout, _ := cmd.StdoutPipe()

// Capture stderr (if any).
var stderr bytes.Buffer
cmd.Stderr = &stderr
cmd.Start()

// Send progress updates.
Expand All @@ -74,8 +80,14 @@ func (f *FFmpeg) Run(input string, output string, data string) {
// Update progress struct.
f.updateProgress(stdout)

cmd.Wait()
err := cmd.Wait()
if err != nil {
fmt.Println(stderr.String())
f.finish()
return err
}
f.finish()
return nil
}

func (f *FFmpeg) updateProgress(stdout io.ReadCloser) {
Expand Down
6 changes: 5 additions & 1 deletion api/worker/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ func encode(job types.Job, probeData *encoder.FFProbeResponse) error {
// Run FFmpeg.
f := &encoder.FFmpeg{}
go trackEncodeProgress(encodeID, probeData, f)
f.Run(job.LocalSource, dest, p.Data)
err = f.Run(job.LocalSource, dest, p.Data)
if err != nil {
close(progressCh)
return err
}
close(progressCh)

// Set encode progress to 100.
Expand Down
2 changes: 2 additions & 0 deletions web/src/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default {

if (redirect) {
context.$router.push({ name: redirect });
context.$router.go();
}
}, (err) => {
console.log(err);
Expand Down Expand Up @@ -50,6 +51,7 @@ export default {
cookie.remove('token');
this.user.authenticated = false;
context.$router.push({ name: 'login' });
context.$router.go();
},

checkAuth(context) {
Expand Down
12 changes: 11 additions & 1 deletion web/src/components/JobsTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,15 @@
:fields="fields"
:items="items">

<template v-slot:cell(status)="data">
<b-badge
:variant="data.item.status === 'error' ? 'danger' : 'primary'"
>{{ data.item.status }}</b-badge>
</template>

<template v-slot:cell(progress)="data">
<b-progress
v-if="data.item.status !== 'error'"
:value="data.item.progress"
:animated="data.value !== 100"
:variant="data.value === 100 ? 'success' : 'primary'"
Expand Down Expand Up @@ -114,7 +121,7 @@ export default {
};
</script>

<style scoped>
<style>
.code {
background-color: #f4f4f4;
border: 1px solid #aaa;
Expand All @@ -123,4 +130,7 @@ export default {
margin-top: 10px;
padding: 5px;
}
#jobs-table .table td {
vertical-align: middle;
}
</style>
2 changes: 1 addition & 1 deletion web/src/components/MachinesTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
striped hover dark
:fields="fields"
:items="items">
<template slot="action" slot-scope="data">
<template v-slot:cell(action)="data">
<b-button variant="light" @click="onClickDelete(data.item.id)">❌</b-button>
</template>
</b-table>
Expand Down
1 change: 1 addition & 0 deletions web/src/components/PresetsTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ export default {
onSubmit(evt) {
evt.preventDefault();
console.log(JSON.stringify(this.form));
this.form.data = JSON.stringify(this.editor.get());
this.updatePreset(this.form);
},
Expand Down

0 comments on commit c21c8a5

Please sign in to comment.