所以,我有一个rake任务作为一个chron任务运行(它在windows上运行,所以这是rufus调度程序),这个特殊的rake任务通过HTTP将数据发送到服务器。如果在HTTP响应正文中发回了特定定义的错误,则使用system
命令运行另一个rake任务。
不幸的是,这是在Windows上运行的。 rake任务连接到数据库并在读取数据库中的每一行时发送数据,因此引发了以下错误,因此它说“上面的路径”是当前目录,并且它没有看到rake任务是可用命令
C:\Users\ALilland\Documents\macros\experiments\core_scripts\app>rake sage_time_records:import
'\\SAGE\TIMBERLINE OFFICE\9.5\ACCOUNTING\GLOBAL'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported. Defaulting to Windows directory.
rake aborted!
No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb, Rakefile.rb)
(See full trace by running task with --trace)
佣金任务
task :import do
## establish connection
# ...
## Print out each row
while row = db_query.fetch do
# ...
## define the payload of what will be sent to API
# ...
begin
url = "#{ENV['API']}/time_records"
print "Sending Time Record to API ... "
response = RestClient.post(url, payload, {accept: :json})
puts 'success' if response.code == 201
rescue RestClient::ExceptionWithResponse => error
puts 'failed' if error.response.code != 201
error_body = JSON.parse(error.response.body)
next if error_body['error'] == 'Job Number not found'
## calling the other rake task and passing a variable
system("rake sage_field_employees:import[\"#{mapped[:employee]}\"]") if error_body['error'] == 'Field Employee not found'
# ...
end
end
# ...
end