From 752ab5cfb8c82570d87f44856850b8c7756f5764 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Wed, 25 Aug 2010 14:49:33 +0200 Subject: opentox-api-wrapper bumped to 1.6.6 --- application.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application.rb b/application.rb index fe3d593..d51e0bd 100644 --- a/application.rb +++ b/application.rb @@ -1,5 +1,5 @@ require 'rubygems' -gem "opentox-ruby-api-wrapper", "= 1.6.5" +gem "opentox-ruby-api-wrapper", "= 1.6.6" require 'opentox-ruby-api-wrapper' #require "dm-is-tree" -- cgit v1.2.3 From 52c02d588147c16dd0b32a7669324519027dbca2 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Fri, 19 Nov 2010 14:42:29 +0100 Subject: lazar predictions and toxcreate are working --- application.rb | 90 ++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 72 insertions(+), 18 deletions(-) diff --git a/application.rb b/application.rb index d51e0bd..b0f0910 100644 --- a/application.rb +++ b/application.rb @@ -1,7 +1,6 @@ require 'rubygems' gem "opentox-ruby-api-wrapper", "= 1.6.6" require 'opentox-ruby-api-wrapper' -#require "dm-is-tree" class Task include DataMapper::Resource @@ -19,35 +18,47 @@ class Task property :title, String, :length => 255 property :creator, String, :length => 255 property :description, Text + + def metadata + { + DC.creator => @creator, + DC.title => @title, + DC.date => @created_at, + OT.hasStatus => @hasStatus, + OT.resultURI => @resultURI, + OT.percentageCompleted => @percentageCompleted, + DC.description => @description, + #:due_to_time => @due_to_timer + } + end end DataMapper.auto_upgrade! +# Get a list of all tasks +# @return [text/uri-list] List of all tasks get '/?' do response['Content-Type'] = 'text/uri-list' Task.all(params).collect{|t| t.uri}.join("\n") + "\n" end +# Get task representation +# @param [Header] Accept Mime type of accepted representation, may be one of `application/rdf+xml,application/x-yaml,text/uri-list` +# @return [application/rdf+xml,application/x-yaml,text/uri-list] Task representation in requested format, Accept:text/uri-list returns URI of the created resource if task status is "Completed" get '/:id/?' do task = Task.get(params[:id]) halt 404, "Task '#{params[:id]}' not found." unless task - - task_content = {:creator => task.creator, :title => task.title, :date => task.created_at, :hasStatus => task.hasStatus, - :resultURI => task.resultURI, :percentageCompleted => task.percentageCompleted, :description => task.description, - :due_to_time => task.due_to_time } - code = task.hasStatus == "Running" ? 202 : 200 case request.env['HTTP_ACCEPT'] - when /application\/x-yaml|\*\/\*/ # matches 'application/x-yaml', '*/*' + when /yaml/ response['Content-Type'] = 'application/x-yaml' - task_content[:uri] = task.uri - halt code, task_content.to_yaml - when /application\/rdf\+xml|\*\/\*/ + halt code, task.metadata.to_yaml + when /application\/rdf\+xml|\*\/\*/ # matches 'application/x-yaml', '*/*' response['Content-Type'] = 'application/rdf+xml' - owl = OpenTox::Owl.create 'Task', task.uri - task_content.each{ |k,v| owl.set(k.to_s,v)} - halt code, owl.rdf + t = OpenTox::Task.new task.uri + t.add_metadata task.metadata + halt code, t.to_rdfxml when /text\/uri\-list/ response['Content-Type'] = 'text/uri-list' halt code, task.resultURI @@ -56,26 +67,65 @@ get '/:id/?' do end end -# dynamic access to Task properties +# Get Task properties. Works for +# - /task/id +# - /task/uri +# - /task/created_at +# - /task/finished_at +# - /task/due_to_time +# - /task/pid +# - /task/resultURI +# - /task/percentageCompleted +# - /task/hasStatus +# - /task/title +# - /task/creator +# - /task/description +# @return [String] Task property get '/:id/:property/?' do response['Content-Type'] = 'text/plain' task = Task.get(params[:id]) halt 404,"Task #{params[:id]} not found." unless task - eval("task.#{params[:property]}").to_s + begin + eval("task.#{params[:property]}").to_s + rescue + halt 404,"Unknown task property #{params[:property]}." + end end +# Create a new task +# @param [optional,String] max_duration +# @param [optional,String] pid +# @param [optional,String] resultURI +# @param [optional,String] percentageCompleted +# @param [optional,String] hasStatus +# @param [optional,String] title +# @param [optional,String] creator +# @param [optional,String] description +# @return [text/uri-list] URI for new task post '/?' do LOGGER.debug "Creating new task with params "+params.inspect max_duration = params.delete(:max_duration.to_s) if params.has_key?(:max_duration.to_s) - task = Task.new(params) - task.save # needed to create id + task = Task.create(params) + #task.save # needed to create id + #LOGGER.debug task.uri task.uri = url_for("/#{task.id}", :full) task.due_to_time = DateTime.parse((Time.parse(task.created_at.to_s) + max_duration.to_f).to_s) if max_duration - raise "could not save" unless task.save + raise "Could not save task #{task.uri}" unless task.save response['Content-Type'] = 'text/uri-list' task.uri + "\n" end +# Change task status. Possible URIs are: ` +# - /task/Cancelled +# - /task/Completed: requires taskURI argument +# - /task/Running +# - /task/Error +# - /task/pid: requires pid argument +# IMPORTANT NOTE: Rack does not accept empty PUT requests. Please send an empty parameter (e.g. with -d '' for curl) or you will receive a "411 Length Required" error. +# @param [optional, String] resultURI URI of created resource, required for /task/Completed +# @param [optional, String] pid Task PID, required for /task/pid +# @param [optional, String] description Task description +# @return [] nil put '/:id/:hasStatus/?' do task = Task.get(params[:id]) @@ -103,6 +153,8 @@ put '/:id/:hasStatus/?' do end +# Delete a task +# @return [text/plain] Status message delete '/:id/?' do task = Task.get(params[:id]) halt 404, "Task #{params[:id]} not found." unless task @@ -116,6 +168,8 @@ delete '/:id/?' do "Task #{params[:id]} deleted." end +# Delete all tasks +# @return [text/plain] Status message delete '/?' do Task.all.each do |task| begin -- cgit v1.2.3 From ca6611821f7fca8d2fee77c63320113589e77d91 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Wed, 24 Nov 2010 11:48:32 +0100 Subject: status 503 for rejected tasks --- application.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/application.rb b/application.rb index b0f0910..e7ec409 100644 --- a/application.rb +++ b/application.rb @@ -106,8 +106,6 @@ post '/?' do LOGGER.debug "Creating new task with params "+params.inspect max_duration = params.delete(:max_duration.to_s) if params.has_key?(:max_duration.to_s) task = Task.create(params) - #task.save # needed to create id - #LOGGER.debug task.uri task.uri = url_for("/#{task.id}", :full) task.due_to_time = DateTime.parse((Time.parse(task.created_at.to_s) + max_duration.to_f).to_s) if max_duration raise "Could not save task #{task.uri}" unless task.save -- cgit v1.2.3 From f522ed3edf73fdcdaccf75e6b6c21f3b2da9fe87 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Wed, 24 Nov 2010 13:10:52 +0100 Subject: opentox-ruby-api-wrapper renamed to opentox-ruby --- application.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application.rb b/application.rb index e7ec409..ffda10d 100644 --- a/application.rb +++ b/application.rb @@ -1,6 +1,6 @@ require 'rubygems' -gem "opentox-ruby-api-wrapper", "= 1.6.6" -require 'opentox-ruby-api-wrapper' +gem "opentox-ruby", "~> 0" +require 'opentox-ruby' class Task include DataMapper::Resource -- cgit v1.2.3 From 2ce3efc21035e622c14688ec8bb4129982f4b0c0 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Wed, 24 Nov 2010 14:43:20 +0100 Subject: opentox-ruby gem in config.ru --- config.ru | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.ru b/config.ru index 489932f..8f73955 100644 --- a/config.ru +++ b/config.ru @@ -1,5 +1,5 @@ require 'rubygems' -require 'opentox-ruby-api-wrapper' +require 'opentox-ruby' require 'config/config_ru' run Sinatra::Application -- cgit v1.2.3 From c89ceb400345efbc4c47e722e7dfa0938f013aab Mon Sep 17 00:00:00 2001 From: mguetlein Date: Thu, 13 Jan 2011 14:17:25 +0100 Subject: fix description loading --- application.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/application.rb b/application.rb index ffda10d..91590a3 100644 --- a/application.rb +++ b/application.rb @@ -27,7 +27,8 @@ class Task OT.hasStatus => @hasStatus, OT.resultURI => @resultURI, OT.percentageCompleted => @percentageCompleted, - DC.description => @description, + #text fields are lazy loaded, using member variable can cause description to be nil + DC.description => description #:due_to_time => @due_to_timer } end @@ -148,7 +149,7 @@ put '/:id/:hasStatus/?' do end halt 500,"could not save task" unless task.save - + end # Delete a task -- cgit v1.2.3 From a5eb942ea6eb61052d1873668c78fe329b7117e0 Mon Sep 17 00:00:00 2001 From: mguetlein Date: Fri, 14 Jan 2011 15:00:55 +0100 Subject: set percentage completed --- application.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/application.rb b/application.rb index 91590a3..917a6f1 100644 --- a/application.rb +++ b/application.rb @@ -39,8 +39,9 @@ DataMapper.auto_upgrade! # Get a list of all tasks # @return [text/uri-list] List of all tasks get '/?' do - response['Content-Type'] = 'text/uri-list' - Task.all(params).collect{|t| t.uri}.join("\n") + "\n" + LOGGER.debug "list all tasks "+params.inspect + response['Content-Type'] = 'text/uri-list' + Task.all(params).collect{|t| t.uri}.join("\n") + "\n" end # Get task representation @@ -124,6 +125,7 @@ end # @param [optional, String] resultURI URI of created resource, required for /task/Completed # @param [optional, String] pid Task PID, required for /task/pid # @param [optional, String] description Task description +# @param [optional, String] percentageCompleted progress value, can only be set while running # @return [] nil put '/:id/:hasStatus/?' do @@ -138,9 +140,14 @@ put '/:id/:hasStatus/?' do halt 402,"no param resultURI when completing task" unless params[:resultURI] task.resultURI = params[:resultURI] task.finished_at = DateTime.now + task.percentageCompleted = 100 task.pid = nil when "pid" task.pid = params[:pid] + when "Running" + halt 400,"Task cannot be set to running after not running anymore" if task.hasStatus!="Running" + task.percentageCompleted = params[:percentageCompleted].to_f + LOGGER.debug "Task " + params[:id].to_s + " set percentage completed to: "+params[:percentageCompleted].to_s when /Cancelled|Error/ Process.kill(9,task.pid) unless task.pid.nil? task.pid = nil -- cgit v1.2.3 From b7a88400107c1985f60060499e0e28b156d91a33 Mon Sep 17 00:00:00 2001 From: mguetlein Date: Thu, 20 Jan 2011 11:30:25 +0100 Subject: disable sinatra built in error handling to allow new ot error handling --- config.ru | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config.ru b/config.ru index 8f73955..8603270 100644 --- a/config.ru +++ b/config.ru @@ -2,4 +2,6 @@ require 'rubygems' require 'opentox-ruby' require 'config/config_ru' run Sinatra::Application +set :raise_errors, false +set :show_exceptions, false -- cgit v1.2.3 From 4ab0164d5295e5d9665e205a221edfa977997a58 Mon Sep 17 00:00:00 2001 From: mguetlein Date: Fri, 21 Jan 2011 12:11:01 +0100 Subject: html support for tasks --- application.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/application.rb b/application.rb index 917a6f1..1cd32e0 100644 --- a/application.rb +++ b/application.rb @@ -40,8 +40,13 @@ DataMapper.auto_upgrade! # @return [text/uri-list] List of all tasks get '/?' do LOGGER.debug "list all tasks "+params.inspect - response['Content-Type'] = 'text/uri-list' - Task.all(params).collect{|t| t.uri}.join("\n") + "\n" + if request.env['HTTP_ACCEPT'] =~ /html/ + response['Content-Type'] = 'text/html' + OpenTox.text_to_html Task.all(params).collect{|t| t.uri}.join("\n") + "\n" + else + response['Content-Type'] = 'text/uri-list' + Task.all(params).collect{|t| t.uri}.join("\n") + "\n" + end end # Get task representation @@ -56,6 +61,9 @@ get '/:id/?' do when /yaml/ response['Content-Type'] = 'application/x-yaml' halt code, task.metadata.to_yaml + when /html/ + response['Content-Type'] = 'text/html' + halt code, OpenTox.text_to_html(task.metadata.to_yaml) when /application\/rdf\+xml|\*\/\*/ # matches 'application/x-yaml', '*/*' response['Content-Type'] = 'application/rdf+xml' t = OpenTox::Task.new task.uri -- cgit v1.2.3 From 4c845ae7305fd5c71f79747f5f7d963edd4f4d22 Mon Sep 17 00:00:00 2001 From: mguetlein Date: Mon, 24 Jan 2011 17:23:16 +0100 Subject: adding field errorReport to task --- application.rb | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/application.rb b/application.rb index 1cd32e0..bb16e19 100644 --- a/application.rb +++ b/application.rb @@ -18,6 +18,8 @@ class Task property :title, String, :length => 255 property :creator, String, :length => 255 property :description, Text + + property :errorReport, Object def metadata { @@ -60,14 +62,19 @@ get '/:id/?' do case request.env['HTTP_ACCEPT'] when /yaml/ response['Content-Type'] = 'application/x-yaml' - halt code, task.metadata.to_yaml + metadata = task.metadata + metadata[OT.errorReport] = task.errorReport if task.errorReport + halt code, metadata.to_yaml when /html/ response['Content-Type'] = 'text/html' - halt code, OpenTox.text_to_html(task.metadata.to_yaml) + metadata = task.metadata + metadata[OT.errorReport] = task.errorReport if task.errorReport + halt code, OpenTox.text_to_html(metadata.to_yaml) when /application\/rdf\+xml|\*\/\*/ # matches 'application/x-yaml', '*/*' response['Content-Type'] = 'application/rdf+xml' t = OpenTox::Task.new task.uri t.add_metadata task.metadata + t.add_error_report task.errorReport if task.errorReport halt code, t.to_rdfxml when /text\/uri\-list/ response['Content-Type'] = 'text/uri-list' @@ -137,10 +144,12 @@ end # @return [] nil put '/:id/:hasStatus/?' do + LOGGER.debug "put to task "+params.inspect task = Task.get(params[:id]) halt 404,"Task #{params[:id]} not found." unless task task.hasStatus = params[:hasStatus] unless /pid/ =~ params[:hasStatus] task.description = params[:description] if params[:description] + task.errorReport = YAML.load(params[:errorReport]) if params[:errorReport] case params[:hasStatus] when "Completed" -- cgit v1.2.3 From 39c988fe6fc4798690c0d6a4e0fa52bb097f670b Mon Sep 17 00:00:00 2001 From: mguetlein Date: Mon, 24 Jan 2011 19:33:14 +0100 Subject: fix task-with-error-report to rdf --- application.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/application.rb b/application.rb index bb16e19..8dbd9fb 100644 --- a/application.rb +++ b/application.rb @@ -74,8 +74,8 @@ get '/:id/?' do response['Content-Type'] = 'application/rdf+xml' t = OpenTox::Task.new task.uri t.add_metadata task.metadata - t.add_error_report task.errorReport if task.errorReport - halt code, t.to_rdfxml + t.add_error_report task.errorReport + halt t.to_rdfxml when /text\/uri\-list/ response['Content-Type'] = 'text/uri-list' halt code, task.resultURI @@ -84,6 +84,7 @@ get '/:id/?' do end end + # Get Task properties. Works for # - /task/id # - /task/uri -- cgit v1.2.3 From dce8c014595c85e991b001718fd2d5e8df7c5562 Mon Sep 17 00:00:00 2001 From: mguetlein Date: Tue, 8 Feb 2011 16:57:19 +0100 Subject: add waiting_for field for tasks --- application.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/application.rb b/application.rb index 8dbd9fb..f8c0e1f 100644 --- a/application.rb +++ b/application.rb @@ -19,6 +19,8 @@ class Task property :creator, String, :length => 255 property :description, Text + property :waiting_for, String, :length => 255 + property :errorReport, Object def metadata @@ -63,11 +65,13 @@ get '/:id/?' do when /yaml/ response['Content-Type'] = 'application/x-yaml' metadata = task.metadata + metadata[OT.waitingFor] = task.waiting_for metadata[OT.errorReport] = task.errorReport if task.errorReport halt code, metadata.to_yaml when /html/ response['Content-Type'] = 'text/html' metadata = task.metadata + metadata[OT.waitingFor] = task.waiting_for metadata[OT.errorReport] = task.errorReport if task.errorReport halt code, OpenTox.text_to_html(metadata.to_yaml) when /application\/rdf\+xml|\*\/\*/ # matches 'application/x-yaml', '*/*' @@ -145,7 +149,6 @@ end # @return [] nil put '/:id/:hasStatus/?' do - LOGGER.debug "put to task "+params.inspect task = Task.get(params[:id]) halt 404,"Task #{params[:id]} not found." unless task task.hasStatus = params[:hasStatus] unless /pid/ =~ params[:hasStatus] @@ -164,9 +167,14 @@ put '/:id/:hasStatus/?' do task.pid = params[:pid] when "Running" halt 400,"Task cannot be set to running after not running anymore" if task.hasStatus!="Running" - task.percentageCompleted = params[:percentageCompleted].to_f - LOGGER.debug "Task " + params[:id].to_s + " set percentage completed to: "+params[:percentageCompleted].to_s + task.waiting_for = params[:waiting_for] if params.has_key?("waiting_for") + if params.has_key?("percentageCompleted") + task.percentageCompleted = params[:percentageCompleted].to_f + #LOGGER.debug "Task " + params[:id].to_s + " set percentage completed to: "+params[:percentageCompleted].to_s + end when /Cancelled|Error/ + OpenTox::Task.find(task.waiting_for).cancel if task.waiting_for + LOGGER.debug("Aborting task "+task.uri.to_s) Process.kill(9,task.pid) unless task.pid.nil? task.pid = nil else -- cgit v1.2.3 From 532ebf4d2e88b6ad982d5e4830a129f374f26bc6 Mon Sep 17 00:00:00 2001 From: mguetlein Date: Wed, 9 Feb 2011 14:08:25 +0100 Subject: fix check for waiting_for --- application.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application.rb b/application.rb index f8c0e1f..47cafa5 100644 --- a/application.rb +++ b/application.rb @@ -173,7 +173,7 @@ put '/:id/:hasStatus/?' do #LOGGER.debug "Task " + params[:id].to_s + " set percentage completed to: "+params[:percentageCompleted].to_s end when /Cancelled|Error/ - OpenTox::Task.find(task.waiting_for).cancel if task.waiting_for + OpenTox::Task.find(task.waiting_for).cancel if task.waiting_for and task.waiting_for.uri? LOGGER.debug("Aborting task "+task.uri.to_s) Process.kill(9,task.pid) unless task.pid.nil? task.pid = nil -- cgit v1.2.3 From 1ea65758e446503c6202696580579ed1f994ce4e Mon Sep 17 00:00:00 2001 From: mguetlein Date: Thu, 10 Feb 2011 16:42:05 +0100 Subject: cancel child task in begin rescue block --- application.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/application.rb b/application.rb index 47cafa5..289ce8d 100644 --- a/application.rb +++ b/application.rb @@ -173,7 +173,14 @@ put '/:id/:hasStatus/?' do #LOGGER.debug "Task " + params[:id].to_s + " set percentage completed to: "+params[:percentageCompleted].to_s end when /Cancelled|Error/ - OpenTox::Task.find(task.waiting_for).cancel if task.waiting_for and task.waiting_for.uri? + if task.waiting_for and task.waiting_for.uri? + # try cancelling the child task + begin + w = OpenTox::Task.find(task.waiting_for) + w.cancel if w.running? + rescue + end + end LOGGER.debug("Aborting task "+task.uri.to_s) Process.kill(9,task.pid) unless task.pid.nil? task.pid = nil -- cgit v1.2.3 From 2dbb5523ea01a2bdec49b5c4403e0f07fb687870 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 24 Feb 2011 11:30:27 +0000 Subject: set :lock, true added --- application.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/application.rb b/application.rb index 289ce8d..f52094c 100644 --- a/application.rb +++ b/application.rb @@ -2,6 +2,8 @@ require 'rubygems' gem "opentox-ruby", "~> 0" require 'opentox-ruby' +set :lock, true + class Task include DataMapper::Resource property :id, Serial -- cgit v1.2.3 From fb36679903857a42b2eaa3efdf081fb7cfa74c32 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 25 Feb 2011 17:52:36 +0000 Subject: ohm/redis backend --- application.rb | 95 +++++++++++++++++++++++++++++++++------------------------- 1 file changed, 54 insertions(+), 41 deletions(-) diff --git a/application.rb b/application.rb index f52094c..446ac86 100644 --- a/application.rb +++ b/application.rb @@ -4,43 +4,53 @@ require 'opentox-ruby' set :lock, true -class Task - include DataMapper::Resource - property :id, Serial - property :uri, String, :length => 255 - property :created_at, DateTime - - property :finished_at, DateTime - property :due_to_time, DateTime - property :pid, Integer - - property :resultURI, String, :length => 255 - property :percentageCompleted, Float, :default => 0 - property :hasStatus, String, :default => "Running" #possible states are: "Cancelled", "Completed", "Running", "Error" - property :title, String, :length => 255 - property :creator, String, :length => 255 - property :description, Text - - property :waiting_for, String, :length => 255 - - property :errorReport, Object +class Task < Ohm::Model + #include DataMapper::Resource + #property :id, Serial + attribute :uri + attribute :created_at + + attribute :finished_at + attribute :due_to_time + attribute :pid + + attribute :resultURI + attribute :percentageCompleted + attribute :hasStatus + attribute :title + attribute :creator + attribute :description + + attribute :waiting_for + + attribute :errorReport def metadata { - DC.creator => @creator, - DC.title => @title, - DC.date => @created_at, - OT.hasStatus => @hasStatus, - OT.resultURI => @resultURI, - OT.percentageCompleted => @percentageCompleted, + DC.creator => creator, + DC.title => title, + DC.date => created_at, + OT.hasStatus => hasStatus, + OT.resultURI => resultURI, + OT.percentageCompleted => percentageCompleted.to_f, #text fields are lazy loaded, using member variable can cause description to be nil DC.description => description #:due_to_time => @due_to_timer } end + +=begin + def id + self.id.to_i + end + def self.create(params) + params[:created_at] = Time.now + super(params) + end +=end end -DataMapper.auto_upgrade! +#DataMapper.auto_upgrade! # Get a list of all tasks # @return [text/uri-list] List of all tasks @@ -48,10 +58,10 @@ get '/?' do LOGGER.debug "list all tasks "+params.inspect if request.env['HTTP_ACCEPT'] =~ /html/ response['Content-Type'] = 'text/html' - OpenTox.text_to_html Task.all(params).collect{|t| t.uri}.join("\n") + "\n" + OpenTox.text_to_html Task.all.collect{|t| t.uri}.join("\n") + "\n" else response['Content-Type'] = 'text/uri-list' - Task.all(params).collect{|t| t.uri}.join("\n") + "\n" + Task.all.collect{|t| t.uri}.join("\n") + "\n" end end @@ -59,7 +69,7 @@ end # @param [Header] Accept Mime type of accepted representation, may be one of `application/rdf+xml,application/x-yaml,text/uri-list` # @return [application/rdf+xml,application/x-yaml,text/uri-list] Task representation in requested format, Accept:text/uri-list returns URI of the created resource if task status is "Completed" get '/:id/?' do - task = Task.get(params[:id]) + task = Task[params[:id]] halt 404, "Task '#{params[:id]}' not found." unless task code = task.hasStatus == "Running" ? 202 : 200 @@ -70,6 +80,7 @@ get '/:id/?' do metadata[OT.waitingFor] = task.waiting_for metadata[OT.errorReport] = task.errorReport if task.errorReport halt code, metadata.to_yaml + #halt code, task.created_at when /html/ response['Content-Type'] = 'text/html' metadata = task.metadata @@ -107,7 +118,7 @@ end # @return [String] Task property get '/:id/:property/?' do response['Content-Type'] = 'text/plain' - task = Task.get(params[:id]) + task = Task[params[:id]] halt 404,"Task #{params[:id]} not found." unless task begin eval("task.#{params[:property]}").to_s @@ -129,10 +140,11 @@ end post '/?' do LOGGER.debug "Creating new task with params "+params.inspect max_duration = params.delete(:max_duration.to_s) if params.has_key?(:max_duration.to_s) - task = Task.create(params) - task.uri = url_for("/#{task.id}", :full) - task.due_to_time = DateTime.parse((Time.parse(task.created_at.to_s) + max_duration.to_f).to_s) if max_duration - raise "Could not save task #{task.uri}" unless task.save + #LOGGER.debug "PARAMS: #{params.inspect}" + task = Task.create :created_at => Time.now, :hasStatus => "Running" + task.update :uri => url_for("/#{task.id}", :full) + #task.due_to_time = DateTime.parse((Time.parse(task.created_at.to_s) + max_duration.to_f).to_s) if max_duration + #raise "Could not save task #{task.uri}" unless task.save response['Content-Type'] = 'text/uri-list' task.uri + "\n" end @@ -151,7 +163,7 @@ end # @return [] nil put '/:id/:hasStatus/?' do - task = Task.get(params[:id]) + task = Task[params[:id]] halt 404,"Task #{params[:id]} not found." unless task task.hasStatus = params[:hasStatus] unless /pid/ =~ params[:hasStatus] task.description = params[:description] if params[:description] @@ -184,7 +196,7 @@ put '/:id/:hasStatus/?' do end end LOGGER.debug("Aborting task "+task.uri.to_s) - Process.kill(9,task.pid) unless task.pid.nil? + Process.kill(9,task.pid.to_i) unless task.pid.nil? task.pid = nil else halt 402,"Invalid value for hasStatus: '"+params[:hasStatus].to_s+"'" @@ -197,14 +209,14 @@ end # Delete a task # @return [text/plain] Status message delete '/:id/?' do - task = Task.get(params[:id]) + task = Task[params[:id]] halt 404, "Task #{params[:id]} not found." unless task begin Process.kill(9,task.pid) unless task.pid.nil? rescue halt 500,"Cannot kill task with pid #{task.pid}" end - task.destroy! + task.delete response['Content-Type'] = 'text/plain' "Task #{params[:id]} deleted." end @@ -214,13 +226,14 @@ end delete '/?' do Task.all.each do |task| begin - Process.kill(9,task.pid) unless task.pid.nil? + Process.kill(9,task.pid.to_i) unless task.pid.nil? + task.delete rescue "Cannot kill task with pid #{task.pid}" end #task.destroy! end - Task.auto_migrate! + #Task.auto_migrate! response['Content-Type'] = 'text/plain' "All tasks deleted." end -- cgit v1.2.3 From 1cce5f19131e8b0b36a69ba96543e046d928d43b Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Sun, 27 Feb 2011 09:32:57 +0100 Subject: code cleanup --- application.rb | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/application.rb b/application.rb index 446ac86..5ad846d 100644 --- a/application.rb +++ b/application.rb @@ -5,8 +5,7 @@ require 'opentox-ruby' set :lock, true class Task < Ohm::Model - #include DataMapper::Resource - #property :id, Serial + attribute :uri attribute :created_at @@ -39,15 +38,6 @@ class Task < Ohm::Model } end -=begin - def id - self.id.to_i - end - def self.create(params) - params[:created_at] = Time.now - super(params) - end -=end end #DataMapper.auto_upgrade! @@ -140,8 +130,9 @@ end post '/?' do LOGGER.debug "Creating new task with params "+params.inspect max_duration = params.delete(:max_duration.to_s) if params.has_key?(:max_duration.to_s) - #LOGGER.debug "PARAMS: #{params.inspect}" - task = Task.create :created_at => Time.now, :hasStatus => "Running" + params[:created_at] = Time.now + params[:hasStatus] = "Running" unless params[:hasStatus] + task = Task.create params task.update :uri => url_for("/#{task.id}", :full) #task.due_to_time = DateTime.parse((Time.parse(task.created_at.to_s) + max_duration.to_f).to_s) if max_duration #raise "Could not save task #{task.uri}" unless task.save @@ -213,12 +204,12 @@ delete '/:id/?' do halt 404, "Task #{params[:id]} not found." unless task begin Process.kill(9,task.pid) unless task.pid.nil? + task.delete + response['Content-Type'] = 'text/plain' + "Task #{params[:id]} deleted." rescue halt 500,"Cannot kill task with pid #{task.pid}" end - task.delete - response['Content-Type'] = 'text/plain' - "Task #{params[:id]} deleted." end # Delete all tasks @@ -228,12 +219,10 @@ delete '/?' do begin Process.kill(9,task.pid.to_i) unless task.pid.nil? task.delete + response['Content-Type'] = 'text/plain' + "All tasks deleted." rescue "Cannot kill task with pid #{task.pid}" end - #task.destroy! end - #Task.auto_migrate! - response['Content-Type'] = 'text/plain' - "All tasks deleted." end -- cgit v1.2.3 From 0917543b4fb73b4049338790561af7fdf050d50b Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Thu, 3 Mar 2011 12:39:23 +0100 Subject: serialized error report --- application.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/application.rb b/application.rb index 5ad846d..7db4ce9 100644 --- a/application.rb +++ b/application.rb @@ -158,7 +158,8 @@ put '/:id/:hasStatus/?' do halt 404,"Task #{params[:id]} not found." unless task task.hasStatus = params[:hasStatus] unless /pid/ =~ params[:hasStatus] task.description = params[:description] if params[:description] - task.errorReport = YAML.load(params[:errorReport]) if params[:errorReport] + #task.errorReport = YAML.load(params[:errorReport]) if params[:errorReport] + task.errorReport = params[:errorReport] if params[:errorReport] case params[:hasStatus] when "Completed" -- cgit v1.2.3 From 8be3ffc4c58dfccf43d6b216fe23dabbf0bd1e2c Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Wed, 9 Mar 2011 12:00:09 +0100 Subject: version bumped to 1.0.0 --- application.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application.rb b/application.rb index 7db4ce9..673cc4d 100644 --- a/application.rb +++ b/application.rb @@ -1,5 +1,5 @@ require 'rubygems' -gem "opentox-ruby", "~> 0" +gem "opentox-ruby", "~> 1" require 'opentox-ruby' set :lock, true -- cgit v1.2.3 From 97821ad3851177f54e1999159ebf0b9987d40a27 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Thu, 10 Mar 2011 11:58:12 +0100 Subject: README updated --- README | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/README b/README index 9eb993f..7122ccf 100644 --- a/README +++ b/README @@ -4,7 +4,8 @@ OpenTox Task * An OpenTox REST Webservice (http://www.opentox.org) * Does _not_ comply to the (incomplete) OpenTox API -REST operations: +REST operations +--------------- Get a list of all tasks GET / - Task URIs 200 Get the status of a task GET /{id}/status - created|started|completed|cancelled 200,404 @@ -17,10 +18,12 @@ Cancel a task PUT /{id}/cancelled "" - Delete a task DELETE /{id} - - 200, 404 Delete all tasks DELETE / - - 200 -IMPORTANT NOTE: My framework does not accept empty PUT requests. Please send an empty parameter (e.g. with -d '' for curl) or you will receive a "411 Length Required" error. +IMPORTANT NOTE: Our framework does not accept empty PUT requests. Please send an empty parameter (e.g. with -d '' for curl) or you will receive a "411 Length Required" error. -More documentation: Source code (application.rb) +API documentation +----------------- -Copyright (c) 2009 Christoph Helma. See LICENSE for details. +http://rdoc.info/github/opentox/task +Copyright (c) 2009-2011 Christoph Helma, Martin Guetlein, Micha Rautenberg, Andreas Maunz, David Vorgrimmler, Denis Gebele. See LICENSE for details. -- cgit v1.2.3