Reputation: 685
I'm currently working on an SSIS Package
update in .Net Framework 4.7
and i'm creating a new C# script Task
.
I am using a legacy script which was originally used, and from the looks of it some time ago.
I wanted to clean up my version of this to follow better practises and be more efficient as I think you should when you go through and clear out the weeds etc, however I am new to SSIS Packages so forgive me.
Basically this retrieves a large DataSet
of string
HTTP
requests from a DB which are used to make request to an external API
and process each record in a loop individually. Add request to a model, then make the request using HttpWebRequest
, store the server response
for that model write back the response for that record etc.
The issue is, that this makes use of HttpWebRequest
for the HTTP requests, so I have updated mine use HttpClient
and Inject
it into my helper methods via the Main
method then use throughout my scripts lifetime.
As HttpClient
only has Async
methods i have used them and awaited
the response
. Im calling the something similar to the below method in a ForEach
Loop to make the request for each record in the DataSet
.
public async System.Threading.Tasks.Task ReqHelper()
{
res = await client.GetAsync(url);
}
Because I have awaited
the response
, but the parent Main
method is synchronous
and cannot be otherwise (I have read that there is a lot of issues if Async and SSIS packages in general), will I run into issues with the responses
going back to different records potentially? I was also worried that it may leave the script task before completing all of the records
in the DataSet
due to being awaited and move on to the next Task in the Packages control flow without finishing.
I have added this (Which I know is bad practise and shouldn't be used) but I wanted to see if there was another way of ensuring that we didn't move to the next task in the control flow:
MyParentAsyncMethod(InputData).GetAwaiter().GetResult();
My worry was that maybe that's why they were using HttpWebRequest
in the first place and I have tried to be clever and make the code better and more up to date.
Forgive me if may if i may be naive in some aspects of this this is my first time working with SSIS packages.
I gladly welcome any advice or assistance from the community on this matter
Upvotes: 1
Views: 74