import{k as h}from"./chunk-2NZJ7CN2.js";import{u}from"./chunk-KRYMOHYF.js";import{Ha as n,m as c,na as a,sa as m}from"./chunk-4BRW6LCZ.js";var k=class e{api=m(h);refresh(t){return this.api.post(`/api/tasks/refresh/${t}`,{})}refreshProjectScripts(t){return this.api.post(`/api/projects/refreshScripts/${t}`,{})}getViews(t){return this.api.get(`/api/tasks/list/${t}`)}getStatus(t){return this.api.get(`/api/tasks/status/${t}`)}start(t){return this.api.post("/api/tasks/start",{taskId:t})}stop(t){return this.api.post("/api/tasks/stop",{taskId:t})}restart(t){return this.api.post("/api/tasks/restart",{taskId:t})}active(){return this.api.get("/api/tasks/active")}getRunLog(t,s=200){let i=new u().set("tail",s.toString());return this.api.get(`/api/tasks/log/run/${t}`,i)}getSyslog(t=200){let s=new u().set("tail",t.toString());return this.api.get("/api/tasks/syslog",s)}static \u0275fac=function(s){return new(s||e)};static \u0275prov=a({token:e,factory:e.\u0275fac,providedIn:"root"})};var d=class e{statusByTask=new Map;sigByTask=new Map;runtimeByTask=new Map;runningCountByProject=new Map;totalRunningCount=n(0);totalRunningCountSignal(){return this.totalRunningCount}setRuntime(t){let s=this.norm(t.taskId),i=this.norm(t.projectId);if(!s||!i)return;let T=this.ensureTaskSignal(s)(),r=this.isBusy(T.status),b=this.isBusy(t.status),o=this.toStatus(t);if(this.ensureTaskSubject(s).next(o),this.ensureTaskSignal(s).set(o),this.ensureRuntimeSignal(s).set(t),r!==b){let p=this.ensureProjectCount(i),g=p();p.set(r?Math.max(0,g-1):g+1);let l=this.totalRunningCount();this.totalRunningCount.set(r?Math.max(0,l-1):l+1)}}status$(t){return this.ensureTaskSubject(t).asObservable()}statusSignal(t){return this.ensureTaskSignal(t)}runtimeSignal(t){return this.ensureRuntimeSignal(t)}hasRunning(t){return this.ensureProjectCount(t)()>0}runningCountSignal(t){return this.ensureProjectCount(t)}snapshot(t){return this.ensureTaskSignal(t)()}toStatus(t){switch(t.status){case"idle":return{status:"idle"};case"running":return{status:"running",pid:t.pid,startedAt:t.startedAt};case"stopping":return{status:"stopping"};case"failed":return{status:"failed",exitCode:t.exitCode??null,signal:t.signal??null,stoppedAt:t.stoppedAt};case"success":return{status:"success",exitCode:t.exitCode??null,signal:t.signal??null,stoppedAt:t.stoppedAt};case"stopped":return{status:"stopped",exitCode:t.exitCode??null,signal:t.signal??null,stoppedAt:t.stoppedAt};default:return{status:"idle"}}}isBusy(t){return t==="running"||t==="stopping"}norm(t){return(t??"").trim()}ensureTaskSubject(t){let s=this.norm(t);return this.statusByTask.has(s)||this.statusByTask.set(s,new c({status:"idle"})),this.statusByTask.get(s)}ensureTaskSignal(t){let s=this.norm(t);return this.sigByTask.has(s)||this.sigByTask.set(s,n({status:"idle"})),this.sigByTask.get(s)}ensureProjectCount(t){let s=this.norm(t);return this.runningCountByProject.has(s)||this.runningCountByProject.set(s,n(0)),this.runningCountByProject.get(s)}ensureRuntimeSignal(t){let s=this.norm(t);return this.runtimeByTask.has(s)||this.runtimeByTask.set(s,n(void 0)),this.runtimeByTask.get(s)}static \u0275fac=function(s){return new(s||e)};static \u0275prov=a({token:e,factory:e.\u0275fac,providedIn:"root"})};export{k as a,d as b};
