diff options
author | Christoph Helma <helma@in-silico.de> | 2010-02-09 12:09:30 +0100 |
---|---|---|
committer | Christoph Helma <helma@in-silico.de> | 2010-02-09 12:09:30 +0100 |
commit | e18b0ffdaf603ee0d96e075b375592f9c60ec33e (patch) | |
tree | aa296e7888ee48ac901a5eb1308a462468619ce8 | |
parent | 97a70bb21b6898d6099c786bc65d3ecf16a8f145 (diff) |
Dataset service with tasks
-rw-r--r-- | application.rb | 53 |
1 files changed, 35 insertions, 18 deletions
diff --git a/application.rb b/application.rb index a74038a..d94ea09 100644 --- a/application.rb +++ b/application.rb @@ -52,25 +52,42 @@ get '/:id/features/?' do end post '/?' do - dataset = Dataset.new - dataset.save - uri = url_for("/#{dataset.id}", :full) - content_type = request.content_type - content_type = "application/rdf+xml" if content_type.nil? - case request.content_type - when "application/rdf+xml" - rdf = request.env["rack.input"].read - d= OpenTox::Dataset.new - d.rdf = rdf - d.uri = uri - else - halt 404, "MIME type \"#{request.content_type}\" not supported." + task = OpenTox::Task.create + pid = Spork.spork(:logger => LOGGER) do + + task.started + LOGGER.debug "Dataset task #{task.uri} started" + + dataset = Dataset.new + dataset.save + uri = url_for("/#{dataset.id}", :full) + content_type = request.content_type + content_type = "application/rdf+xml" if content_type.nil? + case request.content_type + when "application/rdf+xml" + rdf = request.env["rack.input"].read + d= OpenTox::Dataset.new + d.rdf = rdf + d.uri = uri + else + halt 404, "MIME type \"#{request.content_type}\" not supported." + end + LOGGER.debug "Saving dataset #{uri}." + begin + dataset.owl = d.rdf + dataset.uri = uri + dataset.save + task.completed(uri) + rescue => e + LOGGER.error e.message + LOGGER.info e.backtrace + halt 500, "Could not save dataset #{uri}." + end + LOGGER.debug "#{dataset.uri} saved." end - dataset.owl = d.rdf - dataset.uri = uri - dataset.save - print dataset.uri - uri + task.pid = pid + #status 303 # rest client tries to redirect + task.uri end delete '/:id/?' do |