diff --git a/src/main/scala/com/neowit/TcpServer.scala b/src/main/scala/com/neowit/TcpServer.scala index b23d4aeb..5a1e854c 100644 --- a/src/main/scala/com/neowit/TcpServer.scala +++ b/src/main/scala/com/neowit/TcpServer.scala @@ -22,7 +22,7 @@ object MyServer extends App{ } class ServerStart extends AsyncAction { - override def act(): Unit = { + override protected def act(): Unit = { val port = basicConfig.getProperty("port").getOrElse("8888").toInt val timeoutMillis = basicConfig.getProperty("timeoutSec").getOrElse("30").toInt * 1000 val server = new TcpServer(port, timeoutMillis) @@ -48,6 +48,9 @@ class ServerStart extends AsyncAction { } } } + + //implement if need to execute some logic only after main action is complete, e.g. persist data to disk + override protected def finalise(): Unit = {} } object TcpServer { diff --git a/src/main/scala/com/neowit/apex/Runner.scala b/src/main/scala/com/neowit/apex/Runner.scala index b776793c..1f191e1e 100644 --- a/src/main/scala/com/neowit/apex/Runner.scala +++ b/src/main/scala/com/neowit/apex/Runner.scala @@ -103,7 +103,7 @@ class Executor extends Logging { } ActionFactory.getAction(basicConfig, basicConfig.action) match { - case Some(action) => action.act() + case Some(action) => action.execute() case None => } diff --git a/src/main/scala/com/neowit/apex/actions/Action.scala b/src/main/scala/com/neowit/apex/actions/Action.scala index 2e62b3d4..c743579c 100644 --- a/src/main/scala/com/neowit/apex/actions/Action.scala +++ b/src/main/scala/com/neowit/apex/actions/Action.scala @@ -78,12 +78,22 @@ object ActionFactory { } trait Action extends Logging { - def act(): Unit + def execute(): Unit = { + act() + finalise() + } + + //this method should implement main logic of the action + protected def act(): Unit + + //implement if need to execute some logic only after main action is complete, e.g. persist data to disk + protected def finalise(): Unit def load[T <:Action](basicConfig: BasicConfig): T def getHelp: ActionHelp } + abstract class AsyncAction extends Action { protected var _basicConfig: Option[BasicConfig] = None @@ -109,6 +119,10 @@ abstract class ApexAction extends AsyncAction { _session = Some(Session(basicConfig)) this.asInstanceOf[T] } + protected override def finalise(): Unit = { + //make sure that session data is saved to disk + session.storeSessionData() + } //need to def (as opposed to val) to stop from failing when called for help() display without session def config:Config = session.getConfig diff --git a/src/main/scala/com/neowit/apex/actions/Deploy.scala b/src/main/scala/com/neowit/apex/actions/Deploy.scala index dab0abe1..fedcecbe 100644 --- a/src/main/scala/com/neowit/apex/actions/Deploy.scala +++ b/src/main/scala/com/neowit/apex/actions/Deploy.scala @@ -314,6 +314,8 @@ class DeployModified extends Deploy { } //if there were aura files then we have to fetch their ids using Retrieve because Metadata deploy() does not return them AuraMember.updateAuraDefinitionData(session, auraFiles, idsOnly = false) + //dump session data to disk + session.storeSessionData() } diff --git a/src/main/scala/com/neowit/apex/actions/tooling/SaveModified.scala b/src/main/scala/com/neowit/apex/actions/tooling/SaveModified.scala index 395d533f..53d65ea7 100644 --- a/src/main/scala/com/neowit/apex/actions/tooling/SaveModified.scala +++ b/src/main/scala/com/neowit/apex/actions/tooling/SaveModified.scala @@ -423,6 +423,9 @@ class SaveModified extends DeployModified { } } + //dump session data to disk + session.storeSessionData() + config.responseWriter.println("RESULT=SUCCESS") config.responseWriter.println("FILE_COUNT=" + membersMap.size) if (!config.isCheckOnly) {