Commit ee20797c authored by Julian Rother's avatar Julian Rother

Implemented job canceling

parent 17eeeac6
...@@ -17,7 +17,7 @@ static void copy_to_log(int fd) ...@@ -17,7 +17,7 @@ static void copy_to_log(int fd)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int ret, errpipe[2] = {-1, -1}; int ret, canceled = 0, errpipe[2] = {-1, -1};
char *src, *dest; char *src, *dest;
pid_t pid; pid_t pid;
struct pollfd fds = {.fd = -1, .events = POLLIN}; struct pollfd fds = {.fd = -1, .events = POLLIN};
...@@ -48,7 +48,9 @@ int main(int argc, char *argv[]) ...@@ -48,7 +48,9 @@ int main(int argc, char *argv[])
while (1) while (1)
{ {
ping_job(jobid, "running", "{\"log\": \"%s\"}", jescape(get_avlogbuf())); canceled = ping_job(jobid, "running", "{\"log\": \"%s\"}", jescape(get_avlogbuf()));
if (canceled)
kill(pid, SIGINT); /* Stop ffmpeg */
poll(&fds, 1, 15000); poll(&fds, 1, 15000);
if (fds.revents & POLLIN) if (fds.revents & POLLIN)
copy_to_log(fds.fd); copy_to_log(fds.fd);
...@@ -57,7 +59,7 @@ int main(int argc, char *argv[]) ...@@ -57,7 +59,7 @@ int main(int argc, char *argv[])
} }
waitpid(pid, &ret, 0); waitpid(pid, &ret, 0);
if (!WEXITSTATUS(ret)) if (canceled && (WEXITSTATUS(ret) == 255 || (WIFSIGNALED(ret) && WTERMSIG(ret) == SIGINT)))
ping_job(jobid, "finished", "{\"log\": \"%s\"}", jescape(get_avlogbuf())); ping_job(jobid, "finished", "{\"log\": \"%s\"}", jescape(get_avlogbuf()));
else if (WIFSIGNALED(ret)) else if (WIFSIGNALED(ret))
job_failed("Subprocesses was killed by signal %s (%i)", strsignal(WTERMSIG(ret)), WTERMSIG(ret)); job_failed("Subprocesses was killed by signal %s (%i)", strsignal(WTERMSIG(ret)), WTERMSIG(ret));
......
...@@ -247,7 +247,7 @@ void connect_pads(AVFilterInOut **ins, AVFilterInOut **outs) ...@@ -247,7 +247,7 @@ void connect_pads(AVFilterInOut **ins, AVFilterInOut **outs)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int err, i, progress, _progress; int err, i, progress, _progress, canceled;
char *p, *input, *output, *inpath, *outpath, *tmppath, *oldsrcpath; char *p, *input, *output, *inpath, *outpath, *tmppath, *oldsrcpath;
AVFormatContext *demux, *mux; AVFormatContext *demux, *mux;
AVCodecContext **decs, **encs; AVCodecContext **decs, **encs;
...@@ -329,14 +329,16 @@ int main(int argc, char *argv[]) ...@@ -329,14 +329,16 @@ int main(int argc, char *argv[])
progress = 0; progress = 0;
ping_job(jobid, "running", 0); ping_job(jobid, "running", 0);
while (!av_read_frame(demux, &pkt)) while (!canceled && !av_read_frame(demux, &pkt))
{ {
i = pkt.stream_index; i = pkt.stream_index;
_progress = av_rescale_q(pkt.pts, demux->streams[i]->time_base, AV_TIME_BASE_Q)*100/demux->duration; _progress = av_rescale_q(pkt.pts, demux->streams[i]->time_base, AV_TIME_BASE_Q)*100/demux->duration;
if (_progress > progress || !checktime(30)) if (_progress > progress || !checktime(30))
{ {
ping_job(jobid, "running", "{\"progress\": %i, \"log\": \"%s\"}", _progress, canceled = ping_job(jobid, "running", "{\"progress\": %i, \"log\": \"%s\"}", _progress,
jescape(get_avlogbuf())); jescape(get_avlogbuf()));
if (canceled)
job_failed("Job canceled");
progress = _progress; progress = _progress;
} }
filtergraph_send(srcs[i], decs[i], &pkt); filtergraph_send(srcs[i], decs[i], &pkt);
......
...@@ -15,6 +15,7 @@ static size_t curl_write_cb(char *ptr, size_t size, size_t nmemb, void *user) ...@@ -15,6 +15,7 @@ static size_t curl_write_cb(char *ptr, size_t size, size_t nmemb, void *user)
int ping_job(int id, char *state, char *status, ...) int ping_job(int id, char *state, char *status, ...)
{ {
int ret; int ret;
long http_status;
CURL *curl; CURL *curl;
va_list ap; va_list ap;
char *p, *url, *e_host, *e_status, *e_apikey, *e_state; char *p, *url, *e_host, *e_status, *e_apikey, *e_state;
...@@ -48,6 +49,7 @@ int ping_job(int id, char *state, char *status, ...) ...@@ -48,6 +49,7 @@ int ping_job(int id, char *state, char *status, ...)
curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_URL, url);
ret = curl_easy_perform(curl); ret = curl_easy_perform(curl);
free(p); free(p);
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_status);
curl_easy_cleanup(curl); curl_easy_cleanup(curl);
if (ret) if (ret)
{ {
...@@ -56,5 +58,7 @@ int ping_job(int id, char *state, char *status, ...) ...@@ -56,5 +58,7 @@ int ping_job(int id, char *state, char *status, ...)
return -1; return -1;
} }
free(url); free(url);
if (http_status == 205)
return 1; /* Job canceled */
return 0; return 0;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment