66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
# File 'lib/taskr/controllers.rb', line 66
def create
begin
task_data = @input[:task] || @input["0"] || @input
name = task_data[:name]
created_by = @env['REMOTE_HOST']
schedule_method = task_data[:schedule_method]
schedule_when = task_data[:schedule_when]
@task = Task.new(
:name => name,
:created_by => created_by,
:schedule_method => schedule_method,
:schedule_when => schedule_when
)
actions_data = task_data[:actions] || task_data[:action]
raise ArgumentError, "Missing action(s) parameter." if actions_data.blank?
if actions_data.kind_of?(Array)
actions = actions_data
elsif actions_data["0"]
actions = []
actions_data.each do |i,a|
actions << a
end
else
actions = actions_data[:action] || actions_data[:actions] || actions_data
end
actions = [actions] unless actions.kind_of? Array
puts actions.inspect
i = 0
actions.each do |a|
puts a.inspect
action_class_name = a[:action_class_name]
action_class_name = "Taskr::Actions::#{action_class_name}" unless action_class_name =~ /^Taskr::Actions::/
begin
action_class = action_class_name.constantize
unless action_class.include? OpenWFE::Schedulable
raise ArgumentError,
"#{a[:action_class_name].inspect} cannot be used as an action because it does not include the OpenWFE::Schedulable module."
end
rescue NameError
raise ArgumentError,
"#{a[:action_class_name].inspect} is not defined (i.e. there is no such action class)."
end
action = TaskAction.new(:order => a[:order] || i, :action_class_name => action_class_name)
action_class.parameters.each do |p|
action.action_parameters << TaskActionParameter.new(:name => p, :value => a[p])
end
@task.task_actions << action
i += 1
end
unless @task.valid?
@status = 500
return render(:new_task)
end
@task.schedule! Taskr.scheduler
if @task.save
location = "/tasks/#{@task.id}?format=#{@format}"
$LOG.debug "#{@task} saved successfuly. Setting Location header to #{location.inspect}."
@headers['Location'] = location
end
return render(:view_task)
rescue => e
puts e.inspect
puts e.backtrace
raise e
end
end
|