Commits

katox committed 1d2e62e Merge

merge with autoreloading

  • Participants
  • Parent commits e214da8, 08b901f

Comments (0)

Files changed (4)

File fan/app/ApplicationPods.fan

 	Str? podName
 	DefaultSettings defaultSettings
 	Auto? auto
+	Jobs jobs := Jobs()
 	
 	Actor? reloadingActor
 	Future? reloadingFuture
 				appPods.mainPod = auto.curPod
 				appPods.podName = appPods.mainPod?.name
 				
-				Jobs.configure(appPods.mainPod)
+				appPods.jobs.configure(appPods.mainPod)
 				//future1.get
 				
 			}).send(Unsafe(this))
 			reloadingFuture = reloadingActor.send(null)
 		
 		
+		
 		reloadingFuture.get
 		reloadingFuture = null
 	}

File fan/auto/Auto.fan

 			try{
 				exception = null
 				reloadRoutes
+				App.get.appPods.jobs.reload(curPod)
 			}
 			catch(Err e){
 				exception = e

File fan/event/Job.fan

 	virtual Obj? doJob(Obj? msg){
 		null
 	}
+	
+	//On dev mode, this method will  be called everytime a old pod gets unloaded
+	//If this method returns true then a new Job instance of same type will be created on the newly loaded pod
+	//and handleDevLoad will be called on that instance again 
+	virtual Bool handleDevUnload(){
+		return false
+	}
+	
+	virtual Void handleDevLoad(){
+		
+	}
 }
 
 class ClosureInvokeParam{

File fan/event/Jobs.fan

 class Jobs{
-	static Void configure(Pod pod){
+	Job[] running := Job[,]
+	
+	Void configure(Pod pod){
 		pod.types.each|Type type|{
 			if(type.fits(Job#)){
 				try{
 					Job job := type.make
+					running.add(job)
 					job.setup
 				}
 				catch(Err e){
 			}
 		}
 	}
+	
+	Void reload(Pod newPod){
+		Job[,].addAll(running).each|Job runningJob|{
+			unloaded := runningJob.handleDevUnload
+			if(unloaded){
+				newPod.types.each|Type type|{
+					if(type.fits(Job#) && type.qname == runningJob.typeof.qname){
+						running.remove(runningJob)
+						Job job := type.make
+						running.add(job)
+						job.handleDevLoad
+						running.add(job)
+					}
+				}
+			}
+		}	
+	}
 }