-
Notifications
You must be signed in to change notification settings - Fork 0
Send Command ToBatch
The only way to send command to SharpBatch is by HTTP Request to server url when SharpBatch is listening.
The available command are :
- Exec
- Status
The Exec command calls batch execution command, this command require some data.
In the url, you must specify BatchName and BatchAction; on querystring you can specify parameters to pass to BatchAction if present.
For example we need to call this batch.
public class TestBatch
{
public string Class2Method1()
{
return "Class2Method1";
}
}and the web is configured on http://localhost:5000 address; the url to call will be :
http://localhost:5000/Batch/Test/Class2Method1
On the example the batch does not require parameter so the querystring is not send.
But on this case
public class TestBatch
{
public string Class2Method1(string Param1)
{
return "Class2Method1";
}
}the method requires a parameter named Param1, so the url to execute batch will be this
http://localhost:5000/Batch/Exec/Test/Class2Method1?Param1=hello
The response will be :
912a7bad-9eee-42eb-b4be-56922ee31ff3 - Class2Method1
The response contains the SessionId of Batch execution ( 912a7bad-9eee-42eb-b4be-56922ee31ff3 ) and the output of Batch method ("Class2Method1")
For a long running method the best way is to define Async method, so you do not have to wait method execution.
public async Task<Person> Method4()
{
return await Task.Run(() =>
{
var person = new Person()
{
Name = "John Doe",
Address = "Route"
};
return person;
});
}Calling url http://localhost:5000/Batch/Exec/Test/Method4
the response is
1487ee3d-c33f-4ff4-896c-5e299aa29c2f - Batch Started
The Batch execution sessionId (1487ee3d-c33f-4ff4-896c-5e299aa29c2f) and a standard message to report that the Batch as started. In this case the response could be lose. You can send response on the tracking system or other output system like db, file or other.
The status command is used to request Batch execution status. The response is a serialization of Batch execution tracking.
Using this Batch
public class TestBatch
{
public string Class2Method1(string Param1)
{
return "Class2Method1";
}
}the url to call is :
http://localhost:5000/Batch/Staus/?sessionid=45b6c453-543e-4430-b67a-16e31605bdb6
the response will be something like this :
45b6c453-543e-4430-b67a-16e31605bdb6 -
{
"BatchName":"BaseTest",
"SessionId":"912a7bad-9eee-42eb-b4be-56922ee31ff3",
"StartDate":"2017-12-05T16:05:51.0464625+01:00",
"EndDate":"2017-12-05T16:05:51.5898236+01:00",
"Pings":[
],
"State":2,
"Messages":[
],
"Ex":null,
"MachineName":"DESKTOP-ITST6K9"
}