user_controller.rb
function Get-PSVersion {
if (test-path variable:psversiontable) {$psversiontable.psversion} else {[version]"1.0.0.0"}
}
$powershell = Get-PSVersion
if($powershell.Major -le 2 ){
Write-Error "Oh, so sorry, this script requires Powershell 3 (due to convertto-json)"
exit
}
if((Test-Path env:\JAVA_HOME) -eq $false){
Write-Error "Environment variable JAVA_HOME must be set to your java home"
exit
}
curl -XDELETE "http://localhost:9200/planets"
$DIR = "D:\programs\elasticsearch\plugins\elasticsearch-jdbc-1.7.0.1\"
$FEEDER_CLASSPATH="$DIR\lib"
$FEEDER_LOGGER="file://$DIR\bin\log4j2.xml"
java -cp "$FEEDER_CLASSPATH\*" -"Dlog4j.configurationFile=$FEEDER_LOGGER" "org.xbib.tools.Runner" "org.xbib.tools.JDBCImporter" jdbc_sqlserver.json
my_job.rb
class UsersController
def create
MyJob.perform_later
User.create(...)
end
end
配置/初始化/ sucker_punch.rb
class MyJob < ActiveJob::Base
queue_as :default
def perform()
puts "START"
sleep 3
puts "END"
end
end
当我在rails控制台中运行require 'sucker_punch/async_syntax'
Rails.application.configure do
config.active_job.queue_adapter = :sucker_punch
end
时,一切正常,记录器会显示此消息MyJob.perform_later
但是,当我向我的 user_controller 发送http请求时,我在3秒之前没有收到任何响应(这让我觉得该作业没有异步执行),并且记录器显示这个Enqueued MyJob (Job ID: 6c857af8-a8ed-4bd0-918b-4296c4315727) to SuckerPunch(default)
似乎在控制器中使用内联(默认?)适配器,这不是异步的。
ps:我使用Enqueued MyJob (Job ID: e3d698eb-00d8-4849-9496-f01c53fc7217) to Inline(default)
作为http服务器,使用不带ActiveJob的sucker_punch工作正常