Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

Commit

Permalink
Merge pull request #15 from Autodesk-Forge/dev
Browse files Browse the repository at this point in the history
fix 504 gateway timeout error while creating project
  • Loading branch information
JohnOnSoftware authored Dec 13, 2020
2 parents 075a316 + 776e831 commit 1d83dcb
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 7 deletions.
57 changes: 54 additions & 3 deletions BimProjectSetupCommon/DataController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using System;
using System.Data;
using System.Collections.Generic;
using System.Threading;

using NLog;
using System.Linq;
Expand Down Expand Up @@ -403,7 +404,7 @@ private static string GetToken()
}
else return _token;
}
private static List<BimProject> GetProjects()
private static List<BimProject> GetProjects( string sortProp = "updated_at", int limit = 100, int offset = 0)
{
if (_options == null)
{
Expand All @@ -412,7 +413,7 @@ private static List<BimProject> GetProjects()

BimProjectsApi _projectsApi = new BimProjectsApi(GetToken, _options);
List<BimProject> projects = new List<BimProject>();
_projectsApi.GetProjects(out projects);
_projectsApi.GetProjects(out projects, sortProp, limit, offset);
return projects;
}
private static BimProject GetProject(string projId)
Expand Down Expand Up @@ -541,9 +542,59 @@ public static string AddProject(BimProject project, string accountId = null, int

}

bool success = false;
BimProject newProject = null;
IRestResponse response = _projectsApi.PostProject(project, accountId);
return HandleCreateProjectResponse(response, accountId, rowIndex);
if (response.StatusCode == System.Net.HttpStatusCode.Created)
{
newProject = JsonConvert.DeserializeObject<BimProject>(response.Content);
success = true;
}
// In certain case, the BIM 360 backend takes more than 10 seconds to handle the request,
// this will result in 504 gateway timeout error, but the project should be already successfully
// created, add this check to fix this issue.
if( response.StatusCode == System.Net.HttpStatusCode.GatewayTimeout )
{
Thread.Sleep(3000);
List<BimProject> projectList = GetProjects(@"-created_at");
newProject = projectList.FirstOrDefault();
success = newProject != null && newProject.name == project.name;
}
if( success )
{
if (_AllProjects == null)
{
_AllProjects = GetProjects();
}

if (accountId == null)
{
_AllProjects.Add(newProject);
}

if (rowIndex > -1)
{
_projectTable.Rows[rowIndex]["id"] = newProject.id;
_projectTable.Rows[rowIndex]["result"] = ResultCodes.ProjectCreated;
}
Log.Info($"- project {newProject.name} created with ID {newProject.id}!");
return newProject.id;
}
else
{
ResponseContent content = null;
content = JsonConvert.DeserializeObject<ResponseContent>(response.Content);
string msg = ((content != null && content.message != null) ? content.message : null);
if (rowIndex > -1)
{
_projectTable.Rows[rowIndex]["result"] = ResultCodes.Error;
_projectTable.Rows[rowIndex]["result_message"] = msg;
}
Log.Warn($"Status Code: {response.StatusCode.ToString()}\t Message: {msg}");
return "error";
}
}

public static void UpdateProject(BimProject project, int rowIndex = -1)
{
BimProjectsApi _projectsApi = new BimProjectsApi(GetToken, _options);
Expand Down
7 changes: 3 additions & 4 deletions ForgeBimApi/ForgeBimApiWrappers/BimProjectApi.cs
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,12 @@ public IRestResponse PatchProjects(string projectId, BimProject project)
/// </summary>
/// <param name="result">List of all BimProject objects</param>
/// <returns>IRestResponse that indicates the status of the call</returns>
public IRestResponse GetProjects(out List<BimProject> result)
public IRestResponse GetProjects(out List<BimProject> result, string sortProp = "updated_at", int limit = 100, int offset = 0 )
{
int limit = 100 ;
Log.Info($"Querying Projects from AccountID '{options.ForgeBimAccountId}'");
result = new List<BimProject>();
List<BimProject> projects;
IRestResponse response = null;
int offset = 0;
do
{
projects = null;
Expand All @@ -205,8 +203,9 @@ public IRestResponse GetProjects(out List<BimProject> result)
request.Resource = Urls["projects"];
request.AddParameter("AccountId", options.ForgeBimAccountId, ParameterType.UrlSegment);
request.AddHeader("authorization", $"Bearer {Token}");
request.AddParameter("sort", sortProp, ParameterType.QueryString);
request.AddParameter("limit", limit, ParameterType.QueryString);
request.AddParameter("offset", offset, ParameterType.QueryString);
request.AddParameter("offset", offset, ParameterType.QueryString);

response = ExecuteRequest(request);

Expand Down

0 comments on commit 1d83dcb

Please sign in to comment.