@tmatsuo さんの GTUG 東京 I/O 報告会の資料がとてもよく構成されています。
Google App Engine 上で Go 言語を使えるようになりました (Experimental!)。
Python はどうなの?
結局、スピードの問題かな?
Go の標準 http パッケージを使う
func init() {
http.HandleFunc("/", func(w http.ResponseWriter,
request *http.Request)
{
c := appengine.NewContext(request)
fmt.Fprintf(w, "Hello, world! from %s", c.AppID())
})
}
type Greeting struct {
Body string
Date datastore.Time
}
func init() {
http.HandleFunc("/", func(w http.ResponseWriter,
request *http.Request) {
c := appengine.NewContext(request)
greetings := &[]Greeting{}
datastore.NewQuery("Greeting").
Order("-Date").
GetAll(c, greetings)
//...
})
}
type Greeting struct {
Body string
Date datastore.Time
}
func init() {
http.HandleFunc("/save", func(w http.ResponseWriter,
request *http.Request) {
c := appengine.NewContext(request)
g := &Greeting{
Body: request.FormValue("body"),
Date: datastore.SecondsToTime(time.Seconds()),
}
datastore.Put(c, datastore.NewIncompleteKey("Greeting"), g)
http.Redirect(w, request, "/", http.StatusFound)
})
}
SortSpec(expression='author', sort_descending=True, default_value='')
SortSpec(scorer_type=ScorerSpec.CUSTOM, expression='max(count(tag), 5)', sort_descending=True)
Document(
doc_id = next_doc_id(),
fields = [
TextField(name="author", value=current_use().nickname()),
HtmlField(name="comment", value=comment_value),
DateField(name="published", value=datetime.date.today())
]
)index = search_api.get_index(index_name)
response = index.search(SearchRequest(
query='',
cursor=response.cursor, limit=RESULTS_PER_PAGE)
sort_specs=[
SortSpec(expression='author', sort_descending=True, default_value='')
]))
scored_docs = []
for result in response:
scored_docs.append((result.document, result.scores))
class Greeting(db.Model): author = db.UserProperty(searchType=ATOM) comment = db.StringProperty(multiline=True, searchType=HTML) date = db.DateTimeProperty(auto_now_add=true)
g = Greeting(author=current_user, comment='hello')
g_sync.put([search_index_mode=ASYNC_WRITE])
query = db.Query(Greeting)
query.matches('comment:hello AND author:alex@example.com')
results = query.fetch(limit=5)
| URL | GET | POST | DELETE |
|---|---|---|---|
| indexes | meta-data | ||
| indexes/A | meta-data | create index A | delete index A |
| indexes/A/docs | get all docs | delete all docs | |
| indexes/A/docs/X | get doc X | create doc X | delete doc X |
段階的にリリースする模様?
現在は「REST APIの実装が始まったばかり」との事で、一般の開発者達がいつから使えるかは不明!
…とはいえ「既に動作している」事を強調していたし、期待しましょう。
FrontEnd(ユーザからのリクエスト)経由で起動される従来のインスタンスとは別にインスタンスを確保する事ができる。
30秒制限も10分制限も無い、時間制限無く処理を実行出来る。
2種類のインスタンスモード。
backends: - name: memdb class: B8 # mem:1024mb, cpu:4.8GHz instances: 5 - name: tq options: dynamic instances: 10
queueの処理をbackendsで実行したり(処理時間は24h上限)。
taskqueue.add(url='/path/to/my/worker/'
, params={'key': key}, target='tq')
QueueにPull Modeが追加. AppEngineが自動的にtaskを実行するのではなく、taskを明示的にpull(lease&delete)する。
queue: - name: pull-queue mode: pull acl: - user_email: bar@foo.com - user_email: user@gmail.com
各種Google APIと同様に、API Explorer からも実行可能.
http://code.google.com/apis/explorer/#_s=taskqueue&_v=v1beta1sdkを使ってRPCでpull(Lease/Delete)
q = taskqueue.Queue('worker-in-backends')
tasks = q.lease_tasks(30, 100) // timeout:30sec, max:100tasks
if not tasks:
return
for t in tasks:
payload = t.payload
# do something...
q.delete_tasks(tasks)
Trusted test program at http://goo.gl/xcB1E
資料作成が間に合いませんでしたすいません