Skip to content

Instantly share code, notes, and snippets.

The DeferredDispatcher is a way to get around the 30-second limit for App Engine requests. We don't want spin-up to be a "show stopper", and we want every request to have a full 30 seconds to do "real work". We added this to appengine-rack 0.0.7, so folks won't need an additional require. The DeferredDispatcher works by using redirects to break up a loading request into 3 parts.

  1. initialize the jruby runtime and jruby-rack
  2. require the framework, and create a new dispatcher
  3. process the real request, with a full 30 seconds

We are inside jruby-rack, so obviously the runtime and Jruby-rack have initialized, so first we set @runtime to true (from nil) and redirect. Next pass, we notice that the @rack_app is nil, so we require the framework (which can take some time) and create a new dispatcher (these have been passed in as a hash) and redirect. In the final pass, we hand the environment to the dispatcher, to do the original "work" of the request.

require 'openid'
require 'net/http'
require 'appengine-apis/urlfetch'
class MyFetcher < OpenID::StandardFetcher
def fetch(url, body=nil, headers=nil, redirect_limit=REDIRECT_LIMIT)
raise OpenID::FetchingError, "Blank URL: #{url}" if url.blank?
headers ||= {}
headers['User-agent'] ||= USER_AGENT
@jwang
jwang / Gemfile
Created April 24, 2010 00:46
These are the necessary changes to add RESTful JSON (and in the process, fix RESTful XML) to the demo on Gist
# Critical default settings:
disable_system_gems
disable_rubygems
bundle_path '.gems/bundler_gems'
# List gems to bundle here:
gem 'rails_dm_datastore'
gem 'rails', "2.3.5"
gem 'dm-core'
gem "json-jruby"
@jwang
jwang / iPadTest.h
Created May 15, 2010 23:07
header file to test if iPad for Universal Apps
#ifndef UI_USER_INTERFACE_IDIOM
#define IPAD NO
#define OS32PLUS NO
#else
#define IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define OS32PLUS YES
#endif
#
1.
06-02 10:24PM 06.935 /rails/info/properties 500 4674ms 6766cpu_ms 0kb Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3,gzip(gfe)
See details
66.91.76.244 - - [02/Jun/2010:22:24:11 -0700] "GET /rails/info/properties HTTP/1.1" 500 109 "http://jruby-gdata.appspot.com/" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3,gzip(gfe)" "jruby-gdata.appspot.com"
2.
E 06-02 10:24PM 11.331
john-wangs-macbook-pro:dubious jwang392$ ./script/build.sh
testing/SimpleJava.java:3: package javax.servlet.http does not exist
import javax.servlet.http.*;
^
testing/SimpleJava.java:4: package com.google.apphosting.api does not exist
import com.google.apphosting.api.ApiProxy;
^
testing/SimpleJava.java:5: package com.google.apphosting.api.ApiProxy does not exist
import com.google.apphosting.api.ApiProxy.Environment;
^
@jwang
jwang / .gitignore
Created November 9, 2010 07:59
My .gitignore file for iOS, Android and Ruby on Rails development on OSX
# OSX Noise
.DS_Store
# TextMate
*.tmproj
tmtags
# XCode (and ancestors) per-user config (very noisy, and not relevant)
*.mode1
*.mode1v3
@jwang
jwang / Paths.xcconfig
Created February 9, 2011 08:16
Preliminary XCode4 Support for Three20. Paths.xcconfig lives in three20/src/common/Configuration Protect.command lives in three20/src/scripts
//
// Copyright 2009-2011 Facebook
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
@jwang
jwang / License
Created February 16, 2011 20:28
Apple Default License
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
this Apple software constitutes acceptance of these terms. If you do
not agree with these terms, please do not use, install, modify or
redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, Apple grants you a personal, non-exclusive
license, under Apple's copyrights in this original Apple software (the
//
// EGOTitledTableViewCell.h
// EGOClasses
//
// Created by Shaun Harrison on 6/2/09.
// Copyright 2009 enormego. All rights reserved.
//
#import <UIKit/UIKit.h>