var debug=function(e){console.log(e)},http={ajax:function(e,n,t){var s=new Headers;return s.append("Content-Type","application/json"),s.append("X-Requested-With","XMLHttpRequest"),fetch(e,{method:t,headers:s,credentials:"same-origin"})},get:function(e){return this.ajax(e,{},"get")},post:function(e,n){return this.ajax(e,n,"post")},json:function(e,n,t){return this.ajax(e,n,t).then(function(e){return e.json()})}},JobManager={jobs:{},getJob:function(e){return this.jobs[e]},isRunning:function(e){var n=this.jobs[e];return!(!n||!n.running)&&(debug(e+": isRunning"),!0)},start:function(e){this.isRunning(e.id)?debug(jobId+": 任务正在运行中"):(this.jobs[e.id]=e,this.execute(e))},pause:function(e){delete this.jobs[e.id]},fire:function(e){postMessage(e)},execute:function(n){if((n=this.getJob(n.id))&&!n.runing){n.runing=!0;try{var t=this;http.json(n.relUrl+"?c=system&a=job&do=execute&id="+n.id,"","get").then(function(e){0==e.message.errno&&(t.fire(e.message.message),e.message.message.finished||setTimeout(function(){t.execute(n)},1e3))}),n.runing=!1}catch(e){n.runing=!1}return!0}}};onmessage=function(e){var n=e.data;n.start?JobManager.start(n):JobManager.pause(n)};