Question

Just a quick one to see whether it is possible to run a block of code after the bootstrap's init() has completed?

Hows the best way to go about it?

I have some external systems I need to connect to, and I want to show an 'index' page saying 'Connecting to sub systems' or something similar whilst this block completes, and then once its done the application works as normal.

Am I right in thinking you cant access a page until after bootstrap? Is there a simple way to restrict people accessing other parts of the system whilst this service runs? Does this seem feasible?

Cheers for any help!

Was it helpful?

Solution

Based on your requirement as you also pointed out bootstrap is not your friend. you need a view and controller for your screen and a service for your connection logic to external systems. You also need a flag or a method for sanity check of the communication within the scope of application or session. Then I would suggest to create a filter and check if you have the connections, if not redirect them to the controller that will connect it. Sudo:

class ConnectionFilters {
def filters = {
    loginCheck(controller: '*', action: '*') {
        before = {
            if (!session.connection ) {
                redirect(controller:'connection',action: 'connect')
                return false
            }
        }
    }
}

}

class controller {
    def connectionService
    def connect (){
        try {
            connectionService.connectTo('systemx')
            connectionService.connectTo('systemy')
            connectionService.connectTo('systemz')
        }
        catch(e){
            session.connection = false
            redirect view:'error'
        }
        session.connection = true
    }
}


class ConnectionService {
    def connectTo(systemname){
        ....
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top