title: Accessing Sinatra application scope from Rake task
body: <p>I have a global variable in a Sinatra application that I want to update with a scheduled task from my Rakefile. Note that the application is hosted on Heroku. I have set up helpers in order to access this variable.</p>
  
  <pre><code>get '/' do
      @@var
  end
  
  helpers do
      def get_var
          return @@var
      end
  
      def set_var(value)
          @@var = value
      end
  end
  </code></pre>
  
  <p>Here is the task in my Rakefile:</p>
  
  <pre><code>task :do_something do
      Sinatra::Application.set_var(get_data)
  end
  
  def get_data
      # Retrieve value from external source
      ...
      return val
  end
  </code></pre>
  
  <p>The problem I run into is that the task executes properly, but the variable in the Sinatra application is never updated. I assume this is because calling <code>Sinatra::Application</code> from within the Rakefile actually creates a separate instance of the application from the primary instance that I am trying to update.</p>
  
  <p>I want to know if their is a way to access the scope of the running Sinatra web app from within a Rakefile task.</p>
  
  <p>*Note: I could just write the value retrieved in the scheduled task to a database and then access it from the Sinatra app, but that would be overkill because this variable is updated so infrequently but retrieved so regularly that I would prefer to keep it in memory for easier access. I have looked into Memcache and Redis in order to avoid turning to a database, but again I feel that this would be excessive for a single value. Feel free to disagree with this.</p>
  
  <p>EDIT: In regards to Alexey Sukhoviy's comment, Heroku does not allow writing to files outside of the tmp directories, and these are not kept alive long enough to satisfy the needs of the application.</p>