Friday, March 12, 2010

Grails: how to run different logic in production and development environments

There are times when we need to run different stuff depending on the environment the app is running on. For example, integration with external systems are sometimes simulated (mocked) in Development, and are executed for real in Production.

Here's a simple way to run one thing in Development and another in Production (or as many environments as you  need ...).

import grails.util.Environment; 
class MyController{ 
   Environment.executeForCurrentEnvironment { 
      production { 
         // Here goes the prod code
      development { 
         // Here goes the dev code

No comments:

Post a Comment