lib/rest-ftp-daemon/api/jobs.rb in rest-ftp-daemon-0.240.2 vs lib/rest-ftp-daemon/api/jobs.rb in rest-ftp-daemon-0.241
- old
+ new
@@ -5,26 +5,29 @@
class Jobs < Grape::API
####### HELPERS
helpers do
-
def logger
Root.logger
end
-
end
-####### GET /jobs/:id
+####### Common request logging
+ before do
+ log_info "HTTP #{request.request_method} #{request.fullpath}", params
+ end
+
+####### READ ONE JOB
+
+ desc "Read job with ID"
params do
requires :id, type: String, desc: "ID of the Job to read", regexp: /[^\/]+/
end
get "/*id" do
- log_info "GET /jobs/#{params[:id]}"
-
begin
# Get job to display
raise RestFtpDaemon::JobNotFound if params[:id].nil?
job = $queue.find_by_id(params[:id]) || $queue.find_by_id(params[:id], true)
raise RestFtpDaemon::JobNotFound if job.nil?
@@ -43,17 +46,14 @@
end
end
-####### GET /jobs/
+####### READ ALL JOBS
desc "List all Jobs"
-
get "/" do
- log_info "GET /jobs"
-
begin
# Get jobs to display
jobs = $queue.jobs
rescue StandardError => exception
@@ -66,14 +66,13 @@
end
end
-####### POST /jobs/
+####### CREATE A JOB
desc "Create a new job"
-
params do
requires :source, type: String, desc: "Source file pattern"
requires :target, type: String, desc: "Target remote path"
optional :label, type: String, desc: "Descriptive label for this job"
optional :notify, type: String, desc: "URL to get POST'ed notifications back"
@@ -89,16 +88,12 @@
optional :tempfile,
type: Boolean,
desc: "Upload to a temp file before renaming it to the target filename",
default: Settings.at(:transfer, :tempfile)
end
-
post "/" do
- log_info "POST /jobs", params
- log_debug params.to_json
-
+ # log_debug params.to_json
begin
-
# Create a new job
job_id = $queue.generate_id
job = Job.new(job_id, params)
# And push it to the queue