Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Agentless task: Invoke REST API - Timeout question #5876

Closed
mrducnguyen opened this issue Nov 16, 2017 · 10 comments
Assignees
Labels

Comments

@mrducnguyen
Copy link

@mrducnguyen mrducnguyen commented Nov 16, 2017

Hi,

I'm having trouble setting up this task. I implemented a REST API to help with our releases. This is a long running task, about 30 seconds normally, but sometimes it's quicker.

I have setup my Agentless Invoke REST API as following

invokerestapi

My builds keep failing at this step, Invoke REST API task always timed out at 20 seconds regardless how much time I put into the Timeout option...

Sometime when the Release API runs in less than 20 seconds then my builds were good.

I have tried to enable Wait for Completion, but that option always behave like this: the task will wait for exactly the amount of time set in the Timeout option, then failed with Timeout Exception, regardless of the REST API call response was successfully received.

Right now I'm looking at writing my own Powershell script to to this task, but I really want to use what was available.

Thanks,

@pjquirk

This comment has been minimized.

Copy link
Member

@pjquirk pjquirk commented Nov 16, 2017

I believe your assessment is correct. The REST API call retrieves a timeout value from the system that defaults to 20 seconds, and is not configurable nor really related to the timeout shown in the GUI here. If/when the REST request times out, the "done" event is never fired so the task will always wait until the timeout shown in the GUI, and then fail because it never got the "done" event.

@bryanmacfarlane

This comment has been minimized.

Copy link
Contributor

@bryanmacfarlane bryanmacfarlane commented Dec 16, 2017

Not an issue with one of the tasks in this repo (what the issues are tracking): https://github.com/Microsoft/vsts-tasks/tree/master/Tasks

If you're having an issue with the service, you can create something at developer community.

@bansalaseem

This comment has been minimized.

Copy link
Contributor

@bansalaseem bansalaseem commented Dec 20, 2017

Since it is talking about this task, https://github.com/Microsoft/vsts-tasks/tree/master/Tasks/InvokeRestApi, I am reopening the issue.

@bansalaseem bansalaseem reopened this Dec 20, 2017
@bansalaseem

This comment has been minimized.

Copy link
Contributor

@bansalaseem bansalaseem commented Dec 20, 2017

If your task is taking longer than 20 seconds, then you should consider calling back VSTS using the code snippet shared here

@mrducnguyen

This comment has been minimized.

Copy link
Author

@mrducnguyen mrducnguyen commented Jan 15, 2018

Thanks for your information.

I will need to call back to VSTS from our environment using PHP, I guess I can only use the JSON REST API. Can you link me to the REST APIs equivalent to the .NET library used in your snippet?

Much appreciate!

@mrducnguyen

This comment has been minimized.

Copy link
Author

@mrducnguyen mrducnguyen commented Jan 22, 2018

@bansalaseem I have tried to 'reverse engineer' the package you linked in your blog post, I've reached to getting the resource using resource locator, but then sub-sequence calls always returned 500 Internal Server error from VSTS.

I also tried both this https://github.com/Microsoft/vsts-rm-extensions/tree/master/ServerTaskHelper and your code snippet with values on our VSTS task (extract from requestb.in), which returned the same 500 error.

Any ideas with this error?

Here's my Controller

public ActionResult SendLog([FromBody] List<string> messages)
{
    BuildTaskProperties taskProperties;
    taskProperties = GetTaskProperties(Request.Headers);

    string hubName = "release";
    VssConnection connection = new VssConnection(new Uri(taskProperties.VstsUrl), new VssBasicCredential("username", taskProperties.AuthToken));
    var taskClient = connection.GetClient<TaskHttpClient>();

    taskClient.AppendTimelineRecordFeedAsync(
        taskProperties.ProjectId, 
        hubName, 
        taskProperties.PlanId, 
        taskProperties.TimelineId, 
        taskProperties.JobId, 
        new VssJsonCollectionWrapper<IEnumerable<string>>(messages)
    ).SyncResult(); //always throw VssResponseException - Internal Server Error

    // Send task completion event
    taskClient.RaisePlanEventAsync(
        taskProperties.ProjectId, 
        hubName, 
        taskProperties.PlanId, 
        new TaskCompletedEvent(taskProperties.JobId, taskProperties.JobId, TaskResult.Succeeded)
    ).SyncResult();

    return new JsonResult(new {
        message = String.Format("I received [{0}] messages: {1}", messages.Count, String.Join(", ", messages)),
        taskProperties
    });
}

private static BuildTaskProperties GetTaskProperties(IHeaderDictionary headerDictionary)
{
    var taskProperties = new BuildTaskProperties();

    taskProperties.GetType().GetProperties()
        .Where(pi => headerDictionary.ContainsKey(pi.Name))
        .ToList().ForEach(pi => {
            if (pi.PropertyType.Equals(typeof(Guid))) {
                pi.SetValue(taskProperties, Guid.Parse(headerDictionary[pi.Name]), null);
            } else {
                pi.SetValue(taskProperties, headerDictionary[pi.Name].ToString(), null);
            }
        });

    return taskProperties;
}

BuildTaskProperties is just a simple model

public class BuildTaskProperties
{
    public Guid JobId {
        get; set;
    }

    public Guid PlanId {
        get;set;
    }

    public Guid TimelineId {
        get; set;
    }

    public Guid ProjectId {
        get;set;
    }

    public string VstsUrl {
        get;set;
    }

    public string AuthToken {
        get;set;
    }
}

And this is my project reference

    <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.3"/>
    <PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.4-preview1"/>
    <PackageReference Include="Microsoft.AspNet.WebApi.Core" Version="5.2.4-preview1"/>
    <PackageReference Include="Microsoft.TeamFoundation.DistributedTask.Common.Contracts" Version="16.118.0-preview"/>
    <PackageReference Include="Microsoft.TeamFoundation.DistributedTask.WebApi" Version="15.127.0-preview"/>
    <PackageReference Include="Microsoft.VisualStudio.Services.Client" Version="16.118.0-preview"/>
    <PackageReference Include="Microsoft.VisualStudio.Services.Release.Client" Version="15.127.0-preview"/>
    <PackageReference Include="System-Web-Helpers.dll" Version="1.0.1"/>
@bansalaseem

This comment has been minimized.

Copy link
Contributor

@bansalaseem bansalaseem commented Mar 19, 2018

suresh, can you please take a look at the code?

@sureshtadisetty

This comment has been minimized.

Copy link
Member

@sureshtadisetty sureshtadisetty commented Mar 21, 2018

@mrducnguyen, request you to also paste Headers you've defined for this failing Invoke REST API task in your ReleaseDefinition.
Also, do you see any error detail other than Internal Server Error?

@bansalaseem

This comment has been minimized.

Copy link
Contributor

@bansalaseem bansalaseem commented Apr 14, 2018

Since @mrducnguyen has not come back, I am marking the issue as closed.

@mrducnguyen

This comment has been minimized.

Copy link
Author

@mrducnguyen mrducnguyen commented Apr 16, 2018

Hi, sorry for my late response

@sureshtadisetty not really sure what you mean by Headers. What I did was just copy/paste sample codes from the provided GitHub, testing against a simple Invoke REST API Task configured as a step in my build. Also, there is no additional error message apart from "Internal Server error"

I long have switched to PowerShell script to invoke my REST API, even use a loop to wait for server release process result, so it's all good for me now.

Also, I think the default "20 second timeout" including the time to set-up the task, which leaves the real-working part, i.e. the real invocation of the REST API, [much] less than 20 seconds to wait for a response. It's just a "smoke" observation of the task, not basing on concrete code investigation so I could be wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can’t perform that action at this time.