Skip to content

Commit

Permalink
fixed bug - in some cases session data was not persisted to disk
Browse files Browse the repository at this point in the history
  • Loading branch information
neowit committed Mar 6, 2015
1 parent bcadabb commit ba09a2e
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/main/scala/com/neowit/TcpServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/com/neowit/apex/Runner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
}

Expand Down
16 changes: 15 additions & 1 deletion src/main/scala/com/neowit/apex/actions/Action.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/main/scala/com/neowit/apex/actions/Deploy.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit ba09a2e

Please sign in to comment.