Extract out deployment rollout and add tests
This commit is contained in:
parent
128cf0a28d
commit
a6ffe49cba
5 changed files with 140 additions and 72 deletions
|
@ -1,4 +1,4 @@
|
|||
import {Component, EventEmitter, Inject, OnDestroy } from 'ng-metadata/core';
|
||||
import {Component, Inject, OnDestroy } from 'ng-metadata/core';
|
||||
import {AngularPollChannel, PollHandle} from "../../services/services.types";
|
||||
const templateUrl = require('./kube-deploy-modal.component.html');
|
||||
const styleUrl = require('./kube-deploy-modal.css');
|
||||
|
@ -16,6 +16,8 @@ type DeploymentStatus = {
|
|||
pollHandler?: PollHandle,
|
||||
}
|
||||
|
||||
const DEPLOYMENT_POLL_SLEEPTIME = 5000; /* 5 seconds */
|
||||
|
||||
@Component({
|
||||
selector: 'kube-deploy-modal',
|
||||
templateUrl,
|
||||
|
@ -78,12 +80,13 @@ export class KubeDeployModalComponent implements OnDestroy {
|
|||
|
||||
watchDeployments(): void {
|
||||
this.deploymentsStatus.forEach(deployment => {
|
||||
this.AngularPollChannel.create( {
|
||||
const pollChannel = this.AngularPollChannel.create( {
|
||||
// Have to mock the scope object for the poll channel since we're calling into angular1 code
|
||||
// We register the onDestroy function to be called later when this object is destroyed
|
||||
'$on': (_, onDestruction) => { this.onDestroyListeners.push(onDestruction) }
|
||||
}, this.getDeploymentStatus(deployment), 5000 /* 5 seconds */)
|
||||
.start();
|
||||
}, this.getDeploymentStatus(deployment), DEPLOYMENT_POLL_SLEEPTIME);
|
||||
|
||||
pollChannel.start();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -116,6 +119,7 @@ export class KubeDeployModalComponent implements OnDestroy {
|
|||
continue_callback(false);
|
||||
this.state = 'error';
|
||||
this.errorMessage = `Could not cycle the deployments with the new configuration. Error: ${err.toString()}`;
|
||||
this.offerRollback = true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
export interface AngularPollChannel {
|
||||
create(scope: { '$on': Function },
|
||||
requester: (boolean) => void, // function that receives a callback to continue or halt polling
|
||||
opt_sleeptime?: number
|
||||
): PollHandle,
|
||||
create: PollConstructor
|
||||
}
|
||||
|
||||
type PollConstructor = (scope: MockAngularScope, requester: ShouldContinueCallback, opt_sleeptime?: number) => PollHandle;
|
||||
type MockAngularScope = {
|
||||
'$on': Function
|
||||
};
|
||||
type ShouldContinueCallback = (boolean) => void;
|
||||
|
||||
export interface PollHandle {
|
||||
start(opt_skipFirstCall?: boolean): void,
|
||||
stop(): void,
|
||||
|
|
Reference in a new issue