Skip to content

Commit

Permalink
zencoder: set progress to 100 when job status is finished (fixes #170)
Browse files Browse the repository at this point in the history
  • Loading branch information
flavioribeiro committed Dec 5, 2016
1 parent c0d1580 commit 44e3bd5
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 52 deletions.
3 changes: 3 additions & 0 deletions provider/zencoder/zencoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@ func (z *zencoderProvider) JobStatus(job *db.Job) (*provider.JobStatus, error) {
if err != nil {
return nil, fmt.Errorf("error getting job progress: %s", err)
}
if progress.State == "finished" {
progress.JobProgress = 100
}
inputMediaFile := jobDetails.Job.InputMediaFile
return &provider.JobStatus{
ProviderName: Name,
Expand Down
8 changes: 4 additions & 4 deletions provider/zencoder/zencoder_fake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ func (z *FakeZencoder) CancelJob(id int64) error {
}

func (z *FakeZencoder) GetJobProgress(id int64) (*zencoder.JobProgress, error) {
return &zencoder.JobProgress{
State: "processing",
JobProgress: 10,
}, nil
if id == 1234567890 {
return &zencoder.JobProgress{State: "processing", JobProgress: 10}, nil
}
return &zencoder.JobProgress{State: "finished", JobProgress: 0}, nil
}

func (z *FakeZencoder) GetJobDetails(id int64) (*zencoder.JobDetails, error) {
Expand Down
145 changes: 97 additions & 48 deletions provider/zencoder/zencoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -860,62 +860,111 @@ func TestZencoderJobStatus(t *testing.T) {
client: fakeZencoder,
db: dbRepo,
}
jobStatus, err := prov.JobStatus(&db.Job{
ProviderJobID: "1234567890",
})
if err != nil {
t.Fatal(err)
}
resultJSON, err := json.Marshal(jobStatus)
if err != nil {
t.Fatal(err)
}
result := make(map[string]interface{})
err = json.Unmarshal(resultJSON, &result)
if err != nil {
t.Fatal(err)
}
expected := map[string]interface{}{
"providerName": "zencoder",
"providerJobId": "1234567890",
"status": "started",
"progress": float64(10),
"sourceInfo": map[string]interface{}{
"duration": float64(50000000000),
"height": float64(1080),
"width": float64(1920),
"videoCodec": "ProRes422",
},
"providerStatus": map[string]interface{}{
"sourcefile": "http://nyt.net/input.mov",
"created": "2016-11-05T05:02:57Z",
"finished": "2016-11-05T05:02:57Z",
"updated": "2016-11-05T05:02:57Z",
"started": "2016-11-05T05:02:57Z",
var tests = []struct {
ProviderJobID string
Expected map[string]interface{}
}{
{
"1234567890",
map[string]interface{}{
"providerName": "zencoder",
"providerJobId": "1234567890",
"status": "started",
"progress": float64(10),
"sourceInfo": map[string]interface{}{
"duration": float64(50000000000),
"height": float64(1080),
"width": float64(1920),
"videoCodec": "ProRes422",
},
"providerStatus": map[string]interface{}{
"sourcefile": "http://nyt.net/input.mov",
"created": "2016-11-05T05:02:57Z",
"finished": "2016-11-05T05:02:57Z",
"updated": "2016-11-05T05:02:57Z",
"started": "2016-11-05T05:02:57Z",
},
"output": map[string]interface{}{
"destination": "/",
"files": []interface{}{
map[string]interface{}{
"path": "s3://mybucket/destination-dir/output1.mp4",
"container": "mp4",
"videoCodec": "h264",
"height": float64(1080),
"width": float64(1920),
},
map[string]interface{}{
"height": float64(720),
"width": float64(1080),
"path": "s3://mybucket/destination-dir/output2.webm",
"container": "webm",
"videoCodec": "vp8",
},
},
},
},
},
"output": map[string]interface{}{
"destination": "/",
"files": []interface{}{
map[string]interface{}{
"path": "s3://mybucket/destination-dir/output1.mp4",
"container": "mp4",
"videoCodec": "h264",
{
"54321",
map[string]interface{}{
"providerName": "zencoder",
"providerJobId": "54321",
"status": "finished",
"progress": float64(100),
"sourceInfo": map[string]interface{}{
"duration": float64(50000000000),
"height": float64(1080),
"width": float64(1920),
"videoCodec": "ProRes422",
},
map[string]interface{}{
"height": float64(720),
"width": float64(1080),
"path": "s3://mybucket/destination-dir/output2.webm",
"container": "webm",
"videoCodec": "vp8",
"providerStatus": map[string]interface{}{
"sourcefile": "http://nyt.net/input.mov",
"created": "2016-11-05T05:02:57Z",
"finished": "2016-11-05T05:02:57Z",
"updated": "2016-11-05T05:02:57Z",
"started": "2016-11-05T05:02:57Z",
},
"output": map[string]interface{}{
"destination": "/",
"files": []interface{}{
map[string]interface{}{
"path": "s3://mybucket/destination-dir/output1.mp4",
"container": "mp4",
"videoCodec": "h264",
"height": float64(1080),
"width": float64(1920),
},
map[string]interface{}{
"height": float64(720),
"width": float64(1080),
"path": "s3://mybucket/destination-dir/output2.webm",
"container": "webm",
"videoCodec": "vp8",
},
},
},
},
},
}
if !reflect.DeepEqual(result, expected) {
pretty.Fdiff(os.Stderr, expected, result)
t.Errorf("Wrong JobStatus returned. Want %#v. Got %#v.", expected, result)
for _, test := range tests {
jobStatus, err := prov.JobStatus(&db.Job{ProviderJobID: test.ProviderJobID})
if err != nil {
t.Fatal(err)
}
resultJSON, err := json.Marshal(jobStatus)
if err != nil {
t.Fatal(err)
}
result := make(map[string]interface{})
err = json.Unmarshal(resultJSON, &result)
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(result, test.Expected) {
pretty.Fdiff(os.Stderr, test.Expected, result)
t.Errorf("Wrong JobStatus returned. Want %#v. Got %#v.", test.Expected, result)
}
}
}

Expand Down

0 comments on commit 44e3bd5

Please sign in to comment.