Skip to content

Commit

Permalink
Wait-CheckPointTask implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
tkoopman authored Oct 4, 2017
1 parent f3df788 commit 001862e
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 2 deletions.
1 change: 1 addition & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
version: 0.6.{build}
skip_tags: true
only_commits:
files:
- psCheckPoint/
Expand Down
11 changes: 11 additions & 0 deletions docs/extra-content.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@
],
"SubChapters": []
},
{
"Name": "Misc. Commands",
"Cmdlets": [
{
"Name": "Wait-CheckPointTask",
"Class": "WaitCheckPointTask",
"Cmdlet": "Wait-CheckPointTask"
}
],
"SubChapters": []
},
{
"Name": "Misc.",
"Cmdlets": [
Expand Down
5 changes: 4 additions & 1 deletion docs/md/Get-CheckPointTask.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,15 @@ Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept pipeline input: True (ByPropertyName, ByValue)
Accept wildcard characters: False
```
## INPUTS
### System.String
Unique identifier of task
## OUTPUTS
## NOTES
Expand Down
94 changes: 94 additions & 0 deletions docs/md/Wait-CheckPointTask.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Wait-CheckPointTask

## SYNOPSIS
Waits for task to complete.

## SYNTAX

```
Wait-CheckPointTask [-SleepTime <Int32>] [-Timeout <Int32>] -TaskID <String> [-Session] <CheckPointSession>
```

## DESCRIPTION
Waits for task to complete then returns the completed task details.

## EXAMPLES

### ---------- EXAMPLE 1 ----------
```
Install-CheckPointPolicy -Session $Session -PolicyPackage Standard -Targets MyGateway | Wait-CheckPointTask -Session $Session -Verbose
```

## PARAMETERS

### -Session
Session object from Open-CheckPointSession

```yaml
Type: CheckPointSession
Parameter Sets: (All)
Aliases:

Required: True
Position: 0
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -SleepTime
Time in seconds to sleep in-between checking task status
```yaml
Type: Int32
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: 5
Accept pipeline input: False
Accept wildcard characters: False
```
### -TaskID
Unique identifier of task
```yaml
Type: String
Parameter Sets: (All)
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName, ByValue)
Accept wildcard characters: False
```
### -Timeout
Timeout in seconds.
```yaml
Type: Int32
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: 300
Accept pipeline input: False
Accept wildcard characters: False
```
## INPUTS
### System.String
Unique identifier of task
## OUTPUTS
## NOTES
## RELATED LINKS
2 changes: 1 addition & 1 deletion psCheckPoint/Objects/Misc/GetCheckPointTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class GetCheckPointTask : CheckPointCmdlet<CheckPointTasks>
/// <para type="description">Unique identifier of task</para>
/// </summary>
[JsonProperty(PropertyName = "task-id")]
[Parameter(Mandatory = true)]
[Parameter(Mandatory = true, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)]
public string TaskID { get; set; }

/// <summary>
Expand Down
64 changes: 64 additions & 0 deletions psCheckPoint/Objects/Misc/WaitCheckPointTask.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System.Diagnostics;
using System.Linq;
using System.Management.Automation;
using System.Threading;

namespace psCheckPoint.Objects.Misc
{
/// <extra category="Misc. Commands">Wait-CheckPointTask</extra>
/// <summary>
/// <para type="synopsis">Waits for task to complete.</para>
/// <para type="description">Waits for task to complete then returns the completed task details.</para>
/// </summary>
/// <example>
/// <code>Install-CheckPointPolicy -Session $Session -PolicyPackage Standard -Targets MyGateway | Wait-CheckPointTask -Session $Session -Verbose</code>
/// </example>
[Cmdlet(VerbsLifecycle.Wait, "CheckPointTask")]
public class WaitCheckPointTask : GetCheckPointTask
{
/// <summary>
/// <para type="description">Time in seconds to sleep in-between checking task status</para>
/// </summary>
[Parameter]
public int SleepTime { get; set; } = 5;

/// <summary>
/// <para type="description">Timeout in seconds.</para>
/// </summary>
[Parameter]
[ValidateRange(1, 3600)]
public int Timeout { get; set; } = 300;

private Stopwatch watch;

protected override void WriteRecordResponse(CheckPointTasks result)
{
if (watch == null)
{
watch = Stopwatch.StartNew();
}
CheckPointTask task = result.Tasks.First();
if (task == null)
{
throw new System.Exception("Task not found");
}

if (task.ProgressPercentage == 100)
{
WriteVerbose($"Task {task.ProgressPercentage}% complete. Exiting.");
WriteObject(task);
}
else if (watch.ElapsedMilliseconds >= Timeout * 1000)
{
WriteVerbose($"Task {task.ProgressPercentage}% complete. Timeout reached, exiting.");
WriteObject(task);
}
else
{
WriteVerbose($"Task {task.ProgressPercentage}% complete");
Thread.Sleep(SleepTime * 1000);
this.ProcessRecord();
}
}
}
}
1 change: 1 addition & 0 deletions psCheckPoint/psCheckPoint.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Objects\Misc\WaitCheckPointTask.cs" />
<Compile Include="IA\AddCheckPointIdentity.cs" />
<Compile Include="IA\Batch.cs" />
<Compile Include="IA\CheckPointIACmdlet.cs" />
Expand Down

0 comments on commit 001862e

Please sign in to comment.