调用的 Webjob 不考虑传递的参数
Invoked Webjob not considering arguments passed
我正在从应用服务环境中托管的 WebApp 调用 Web 作业。我用来调用的代码如下:
string userName = "$xxxx";
string userPassword = "xxxxx";
string webJobName = "xxxx";
var unEncodedString = String.Format($"{ userName}:{ userPassword}");
var encodedString = Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(unEncodedString));
string URL = string.Format("https://xxxx.scm.azurewebsites.net/api/triggeredwebjobs/" + webJobName + "/run?arguments={0}", jobId.ToString());
System.Net.WebRequest request = System.Net.WebRequest.Create(URL);
request.Method = "POST";
request.ContentLength = 0;
request.Headers["Authorization"] = "Basic " +encodedString;
response = request.GetResponse();
我正在调用一个 Web 作业,它是一个控制台应用程序。我在控制台应用程序中处理参数的方式如下:
static void Main(string[] args)
{
//
var id = 0;
if (args.Length > 0)
{
if (!int.TryParse(args[0].ToString(), out id))
id = 0;
}
if (id > 0)
{
EmailJobExecution emailServ = new EmailJobExecution();
EmailJobDBContext jobDB = new EmailJobDBContext();
var jobs = jobDB.getActiveJob(id);
List<string> logs = new List<string>();
emailServ.ExecuteJob(jobs, out logs);
foreach (var item in logs)
{
Console.WriteLine(item);
}
}
}
问题是我可以在 Webjob 仪表板中看到调用了 webjob,但未传递参数。日志显示为:
[05/30/2017 11:18:51 > 738495: SYS INFO] Status changed to
Initializing
[05/30/2017 11:18:51 > 738495: SYS INFO] Run script 'run.cmd' with
script host - 'WindowsScriptHost'
[05/30/2017 11:18:51 > 738495: SYS INFO] Status changed to Running
[05/30/2017 11:18:51 > 738495: INFO]
[05/30/2017 11:18:51 > 738495: INFO]
D:\local\Temp\jobs\triggered\xxxxx\rwjgkw42.ann>xxxx.EXE
[05/30/2017 11:18:51 > 738495: SYS INFO] Status changed to Success
如果我转到 App Service Editor 并像这样修改 run.cmd:xxxx.EXE 1
(1 是参数)然后我的控制台会像这样获取参数和日志:
[05/30/2017 10:17:26 > 738495: SYS INFO] Status changed to
Initializing
[05/30/2017 10:17:27 > 738495: SYS INFO] Run script 'run.cmd' with
script host - 'WindowsScriptHost'
[05/30/2017 10:17:27 > 738495: SYS INFO] Status changed to Running
[05/30/2017 10:17:27 > 738495: INFO]
[05/30/2017 10:17:27 > 738495: INFO]
D:\local\Temp\jobs\triggered\xxxx\bvck11x1.f3v>xxx.EXE
1
[05/30/2017 10:17:32 > 738495: INFO] 5/30/2017 10:17:27 AM: Job No. 1
Started
[05/30/2017 10:17:32 > 738495: INFO] Message Count: 1
[05/30/2017 10:17:32 > 738495: INFO] 1:OK
[05/30/2017 10:17:32 > 738495: INFO] Status Count: 1
[05/30/2017 10:17:32 > 738495: INFO] 5/30/2017 10:17:32 AM: Job No. 1
Completed
[05/30/2017 10:17:32 > 738495: SYS INFO] Status changed to Success
即使我在Postman中运行 URL,Argument也不通过
请帮我解决这个问题。
Update 31st May 2017:
The Zip Package for Webjobs had the following:
- run.cmd
- xxxx.EXE
and as @SuwatCh guided me, I removed the run.cmd
and leaving only the
*.exe
in Zip Package and then created the WebJob and finally it worked!
以这种方式传递参数应该没问题。请使用最小的应用程序进行测试,因为您所做的与 EmailJobExecution 相关的所有事情都与问题无关,应该省略。此外,如果您还使用邮递员进行复制,则您的客户端代码与问题无关,因此请忽略它。
例如我刚刚尝试了一个简单的批处理文件,其中只包含:
echo Hello Azure WebJob!
echo command line arg %1
echo env variable %WEBJOBS_COMMAND_ARGUMENTS%
并且 %1
和 %WEBJOBS_COMMAND_ARGUMENTS%
都正确地具有传入的值。
之所以这样没有相应地工作,是因为 Zip 包确实有我自己的 run.cmd。
Prior to the resolution I had in my Zip Package are:
- run.cmd
- *.dlls
- xxxx.EXE
为了解决这个问题,我不得不删除 Zip 包中的 run.cmd
,它成功了! :)
我正在从应用服务环境中托管的 WebApp 调用 Web 作业。我用来调用的代码如下:
string userName = "$xxxx";
string userPassword = "xxxxx";
string webJobName = "xxxx";
var unEncodedString = String.Format($"{ userName}:{ userPassword}");
var encodedString = Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(unEncodedString));
string URL = string.Format("https://xxxx.scm.azurewebsites.net/api/triggeredwebjobs/" + webJobName + "/run?arguments={0}", jobId.ToString());
System.Net.WebRequest request = System.Net.WebRequest.Create(URL);
request.Method = "POST";
request.ContentLength = 0;
request.Headers["Authorization"] = "Basic " +encodedString;
response = request.GetResponse();
我正在调用一个 Web 作业,它是一个控制台应用程序。我在控制台应用程序中处理参数的方式如下:
static void Main(string[] args)
{
//
var id = 0;
if (args.Length > 0)
{
if (!int.TryParse(args[0].ToString(), out id))
id = 0;
}
if (id > 0)
{
EmailJobExecution emailServ = new EmailJobExecution();
EmailJobDBContext jobDB = new EmailJobDBContext();
var jobs = jobDB.getActiveJob(id);
List<string> logs = new List<string>();
emailServ.ExecuteJob(jobs, out logs);
foreach (var item in logs)
{
Console.WriteLine(item);
}
}
}
问题是我可以在 Webjob 仪表板中看到调用了 webjob,但未传递参数。日志显示为:
[05/30/2017 11:18:51 > 738495: SYS INFO] Status changed to Initializing
[05/30/2017 11:18:51 > 738495: SYS INFO] Run script 'run.cmd' with script host - 'WindowsScriptHost'
[05/30/2017 11:18:51 > 738495: SYS INFO] Status changed to Running
[05/30/2017 11:18:51 > 738495: INFO]
[05/30/2017 11:18:51 > 738495: INFO] D:\local\Temp\jobs\triggered\xxxxx\rwjgkw42.ann>xxxx.EXE
[05/30/2017 11:18:51 > 738495: SYS INFO] Status changed to Success
如果我转到 App Service Editor 并像这样修改 run.cmd:xxxx.EXE 1
(1 是参数)然后我的控制台会像这样获取参数和日志:
[05/30/2017 10:17:26 > 738495: SYS INFO] Status changed to Initializing
[05/30/2017 10:17:27 > 738495: SYS INFO] Run script 'run.cmd' with script host - 'WindowsScriptHost'
[05/30/2017 10:17:27 > 738495: SYS INFO] Status changed to Running
[05/30/2017 10:17:27 > 738495: INFO]
[05/30/2017 10:17:27 > 738495: INFO] D:\local\Temp\jobs\triggered\xxxx\bvck11x1.f3v>xxx.EXE 1
[05/30/2017 10:17:32 > 738495: INFO] 5/30/2017 10:17:27 AM: Job No. 1 Started
[05/30/2017 10:17:32 > 738495: INFO] Message Count: 1
[05/30/2017 10:17:32 > 738495: INFO] 1:OK
[05/30/2017 10:17:32 > 738495: INFO] Status Count: 1
[05/30/2017 10:17:32 > 738495: INFO] 5/30/2017 10:17:32 AM: Job No. 1 Completed
[05/30/2017 10:17:32 > 738495: SYS INFO] Status changed to Success
即使我在Postman中运行 URL,Argument也不通过
请帮我解决这个问题。
Update 31st May 2017:
The Zip Package for Webjobs had the following:
- run.cmd
- xxxx.EXE
and as @SuwatCh guided me, I removed the
run.cmd
and leaving only the*.exe
in Zip Package and then created the WebJob and finally it worked!
以这种方式传递参数应该没问题。请使用最小的应用程序进行测试,因为您所做的与 EmailJobExecution 相关的所有事情都与问题无关,应该省略。此外,如果您还使用邮递员进行复制,则您的客户端代码与问题无关,因此请忽略它。
例如我刚刚尝试了一个简单的批处理文件,其中只包含:
echo Hello Azure WebJob!
echo command line arg %1
echo env variable %WEBJOBS_COMMAND_ARGUMENTS%
并且 %1
和 %WEBJOBS_COMMAND_ARGUMENTS%
都正确地具有传入的值。
之所以这样没有相应地工作,是因为 Zip 包确实有我自己的 run.cmd。
Prior to the resolution I had in my Zip Package are:
- run.cmd
- *.dlls
- xxxx.EXE
为了解决这个问题,我不得不删除 Zip 包中的 run.cmd
,它成功了! :)