Not able to store data in database

15 Replies
Denis
Denis9mo ago
$details
MODiX
MODiX9mo ago
When you ask a question, make sure you include as much detail as possible. Such as code, the issue you are facing, and what you expect the result to be. Upload code here https://paste.mod.gg/ (see $code for more information on how to paste your code)
clever_cottonmouth
clever_cottonmouthOP9mo ago
Basically i want to store json data in database which is coming from jira api
FusedQyou
FusedQyou9mo ago
That still doesn't clear it up What happends? An error? Does the code run at all?
clever_cottonmouth
clever_cottonmouthOP9mo ago
using (var context = _contextResolver()) { List<JiraRelease> fullAPIList = new List<JiraRelease>(); List<Project> projects = context.Projects.ToList(); foreach (Project project in projects) { string _url = $"rest/api/3/project/{project.Key}/version"; var jsonObject = await _jiraClient.GetAsync(_url);

if (jsonObject["values"] != null && jsonObject.HasValues) { List<JiraRelease> release = jsonObject["values"]. Select(x => { JiraRelease data = new JiraRelease(); data.FixVersionID = x.Value<string>("id"); data.ProjectKey = project.Key; data.FixVersion = x.Value<string>("name"); int statusInt = x.Value<string>("released") == "true" ? 1 : 0;
data.Status = statusInt.ToString(); data.ReleaseDate = x.Value<string>("releaseDate"); return data; }).ToList(); here i am iterating project.Key after that i got response from api but i am getting error to much request i don't know how to handle
FusedQyou
FusedQyou9mo ago
So what happens? Does the code run the loop but throw the error after a few iterations? It's important you share details with us because right now it's still guesswork Try calling the code and see how often the loop is called by logging an integer or something
clever_cottonmouth
clever_cottonmouthOP9mo ago
yes it fail after some looping, I have share completed code above
FusedQyou
FusedQyou9mo ago
Right, but how many iterations is this actually?
FusedQyou
FusedQyou9mo ago
That's not answering my question
clever_cottonmouth
clever_cottonmouthOP9mo ago
it depends the how much project key we have in our database List<Project> projects = context.Projects.ToList(); foreach (Project project in projects)
FusedQyou
FusedQyou9mo ago
Either way the Jira client throws the error so this is not related to your code but rather Jira telling you to request less often. So perhaps you should add a delay between calls and see if that improves it IDK how many calls can be done since I never used this but try adding Task.Delay in the loop and wait like 5 seconds between calls If that fixes it, perhaps you need a sort of throttle that waits between calls if you get an error like this
clever_cottonmouth
clever_cottonmouthOP9mo ago
i dont think so jira have time limiting we can hit jira api reapeatedely
FusedQyou
FusedQyou9mo ago
Your code is not the thing that is going to complaina bout "too many requests", it is definitely the call to Jira But if you are certain that's not the case then actually test the code instead of assuming it's not the case For example, set breakpoints and follow the code step-by-step. Or use a try-catch and handle the error so you know where the code threw the exception
clever_cottonmouth
clever_cottonmouthOP9mo ago
ok i can try that also i will let know once it work
Want results from more Discord servers?
Add your server