Deployment Client API
Track your software deployments metadata with Rollbar
Module/package: Rollbar.Deploys
Namespace: RollbarDeploys
Rollbar Deployment API implements deployment tracking as a REST-based service.
The Rollbar Core module of the SDK includes .NET compatible client to the Deployment API.
The key API type is the RollbarDeploysManager
that implements IRollbarDeploysManager
interfaces. The interface defines async methods for
- registering new deployment instance,
- querying registered deployment instances page-by-page,
- and querying deployment instance details by specified
deploymentID
.
The RollbarDeploysManager
does not have default parameterless constructor defined since it needs some required parameters to be provided at construction time, like Rollbar write and/or read access tokens. Once properly constructed it can be used for deployment registration (by supplying a valid instance of the Deployment
class) and querying for previously registered deployments:
// create a deploys manager:
IRollbarDeploysManager deploysManager =
RollbarDeploysManagerFactory.CreateRollbarDeploysManager(
RollbarUnitTestSettings.AccessToken,
RollbarUnitTestSettings.DeploymentsReadAccessToken
);
// create a new deployment:
var deployment = DeploymentFactory.CreateDeployment(
environment: RollbarUnitTestSettings.Environment,
revision: "99909a3a5a3dd4363f414161f340b582bb2e999",
comment: "Some new unit test deployment @ " + DateTimeOffset.Now,
localUserName: "UnitTestRunner",
rollbarUserName: "rollbar"
);
// register the deployment:
var task = deploysManager.RegisterAsync(deployment);
task.Wait(TimeSpan.FromSeconds(3));
// get all the registered deployments:
var deployments = GetAllDeployments();
// get the very first deployment's details:
var latestDeployment = deployments.FirstOrDefault();
var getDeploymentTask = deploysManager.GetDeploymentAsync(latestDeployment.DeployID);
getDeploymentTask.Wait(TimeSpan.FromSeconds(3));
var deploymentDetails = getDeploymentTask.Result;
where GetAllDeployments() could be implemented as:
private ICollection<IDeploymentDetails> GetAllDeployments()
{
List<IDeploymentDetails> deployments = new List<IDeploymentDetails>();
int pageCount = 0;
int pageItems = 0;
do
{
var task = this._deploysManager.GetDeploymentsPageAsync(
RollbarUnitTestSettings.Environment,
++pageCount
);
task.Wait(TimeSpan.FromSeconds(3));
pageItems = task.Result.Length;
if (pageItems > 0)
{
deployments.AddRange(task.Result);
}
}
while (pageItems > 0);
return deployments;
}
Updated 12 months ago