Skip to content

Commit 656d8d5

Browse files
committed
add tasks functions
1 parent 1c13f74 commit 656d8d5

File tree

2 files changed

+73
-19
lines changed

2 files changed

+73
-19
lines changed

index.js

Lines changed: 61 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class ServerlessStepFunctions {
4646
deploy: {
4747
commands: {
4848
stepf: {
49-
usage: 'Deploy Step functions',
49+
usage: 'Deploy the State Machine of Step functions',
5050
lifecycleEvents: [
5151
'deploy',
5252
],
@@ -66,6 +66,27 @@ class ServerlessStepFunctions {
6666
},
6767
},
6868
},
69+
tasks: {
70+
usage: 'Deploy the Tasks of Step functions',
71+
lifecycleEvents: [
72+
'deploy',
73+
],
74+
options: {
75+
state: {
76+
usage: 'Name of the Tasks',
77+
shortcut: 't',
78+
required: true,
79+
},
80+
stage: {
81+
usage: 'Stage of the service',
82+
shortcut: 's',
83+
},
84+
region: {
85+
usage: 'Region of the service',
86+
shortcut: 'r',
87+
},
88+
},
89+
},
6990
},
7091
},
7192
remove: {
@@ -91,6 +112,27 @@ class ServerlessStepFunctions {
91112
},
92113
},
93114
},
115+
tasks: {
116+
usage: 'Remove the Tasks of Step functions',
117+
lifecycleEvents: [
118+
'deploy',
119+
],
120+
options: {
121+
state: {
122+
usage: 'Name of the Tasks',
123+
shortcut: 't',
124+
required: true,
125+
},
126+
stage: {
127+
usage: 'Stage of the service',
128+
shortcut: 's',
129+
},
130+
region: {
131+
usage: 'Region of the service',
132+
shortcut: 'r',
133+
},
134+
},
135+
},
94136
},
95137
},
96138
invoke: {
@@ -131,15 +173,19 @@ class ServerlessStepFunctions {
131173

132174
this.hooks = {
133175
'deploy:stepf:deploy': () => BbPromise.bind(this)
134-
.then(this.deploy),
176+
.then(this.stateMachineDeploy),
135177
'remove:stepf:remove': () => BbPromise.bind(this)
136-
.then(this.remove),
178+
.then(this.stateMachineRemove),
137179
'invoke:stepf:invoke': () => BbPromise.bind(this)
138-
.then(this.invoke),
180+
.then(this.stateMachineInvoke),
181+
'deploy:tasks:deploy': () => BbPromise.bind(this)
182+
.then(this.tasksDeploy),
183+
'remove:tasks:remove': () => BbPromise.bind(this)
184+
.then(this.tasksRemove),
139185
};
140186
}
141187

142-
deploy() {
188+
stateMachineDeploy() {
143189
this.serverless.cli.log(`Start to deploy ${this.options.state} step function...`);
144190
return BbPromise.bind(this)
145191
.then(this.yamlParse)
@@ -151,7 +197,7 @@ class ServerlessStepFunctions {
151197
.then(this.createStateMachine);
152198
}
153199

154-
remove() {
200+
stateMachineRemove() {
155201
return BbPromise.bind(this)
156202
.then(this.deleteIamRole)
157203
.then(this.getStateMachineArn)
@@ -162,14 +208,22 @@ class ServerlessStepFunctions {
162208
});
163209
}
164210

165-
invoke() {
211+
stateMachineInvoke() {
166212
return BbPromise.bind(this)
167213
.then(this.parseInputdate)
168214
.then(this.getStateMachineArn)
169215
.then(this.startExecution)
170216
.then(this.describeExecution);
171217
}
172218

219+
tasksDeploy() {
220+
// todo
221+
}
222+
223+
tasksRemove() {
224+
// todo
225+
}
226+
173227
getIamRoleName() {
174228
let name = `${this.service}-${this.region}-${this.stage}-${this.options.state}-`;
175229
name += 'ssf-exerole';

index.test.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,31 +73,31 @@ describe('ServerlessStepFunctions', () => {
7373

7474
it('should run deploy:stepf:deploy promise chain in order', () => {
7575
const deployStub = sinon
76-
.stub(serverlessStepFunctions, 'deploy').returns(BbPromise.resolve());
76+
.stub(serverlessStepFunctions, 'stateMachineDeploy').returns(BbPromise.resolve());
7777
return serverlessStepFunctions.hooks['deploy:stepf:deploy']()
7878
.then(() => {
7979
expect(deployStub.calledOnce).to.be.equal(true);
80-
serverlessStepFunctions.deploy.restore();
80+
serverlessStepFunctions.stateMachineDeploy.restore();
8181
});
8282
});
8383

8484
it('should run remove:stepf:remove promise chain in order', () => {
8585
const removeStub = sinon
86-
.stub(serverlessStepFunctions, 'remove').returns(BbPromise.resolve());
86+
.stub(serverlessStepFunctions, 'stateMachineRemove').returns(BbPromise.resolve());
8787
return serverlessStepFunctions.hooks['remove:stepf:remove']()
8888
.then(() => {
8989
expect(removeStub.calledOnce).to.be.equal(true);
90-
serverlessStepFunctions.remove.restore();
90+
serverlessStepFunctions.stateMachineRemove.restore();
9191
});
9292
});
9393

9494
it('should run invoke:stepf:invoke promise chain in order', () => {
9595
const invokeStub = sinon
96-
.stub(serverlessStepFunctions, 'invoke').returns(BbPromise.resolve());
96+
.stub(serverlessStepFunctions, 'stateMachineInvoke').returns(BbPromise.resolve());
9797
return serverlessStepFunctions.hooks['invoke:stepf:invoke']()
9898
.then(() => {
9999
expect(invokeStub.calledOnce).to.be.equal(true);
100-
serverlessStepFunctions.invoke.restore();
100+
serverlessStepFunctions.stateMachineInvoke.restore();
101101
});
102102
});
103103

@@ -107,7 +107,7 @@ describe('ServerlessStepFunctions', () => {
107107
});
108108
});
109109

110-
describe('#deploy()', () => {
110+
describe('#stateMachineDeploy()', () => {
111111
it('should run promise chain in order', () => {
112112
const yamlParseStub = sinon
113113
.stub(serverlessStepFunctions, 'yamlParse').returns(BbPromise.resolve());
@@ -124,7 +124,7 @@ describe('ServerlessStepFunctions', () => {
124124
const createStateMachineStub = sinon
125125
.stub(serverlessStepFunctions, 'createStateMachine').returns(BbPromise.resolve());
126126

127-
return serverlessStepFunctions.deploy()
127+
return serverlessStepFunctions.stateMachineDeploy()
128128
.then(() => {
129129
expect(yamlParseStub.calledOnce).to.be.equal(true);
130130
expect(getStateMachineArnStub.calledAfter(yamlParseStub)).to.be.equal(true);
@@ -145,7 +145,7 @@ describe('ServerlessStepFunctions', () => {
145145
});
146146
});
147147

148-
describe('#remove()', () => {
148+
describe('#stateMachineRemove()', () => {
149149
it('should run promise chain in order', () => {
150150
const deleteIamRoleStub = sinon
151151
.stub(serverlessStepFunctions, 'deleteIamRole').returns(BbPromise.resolve());
@@ -154,7 +154,7 @@ describe('ServerlessStepFunctions', () => {
154154
const deleteStateMachineStub = sinon
155155
.stub(serverlessStepFunctions, 'deleteStateMachine').returns(BbPromise.resolve());
156156

157-
return serverlessStepFunctions.remove()
157+
return serverlessStepFunctions.stateMachineRemove()
158158
.then(() => {
159159
expect(deleteIamRoleStub.calledOnce).to.be.equal(true);
160160
expect(getStateMachineArnStub.calledAfter(deleteIamRoleStub)).to.be.equal(true);
@@ -166,7 +166,7 @@ describe('ServerlessStepFunctions', () => {
166166
});
167167
});
168168

169-
describe('#invoke()', () => {
169+
describe('#stateMachineInvoke()', () => {
170170
it('should run promise chain in order', () => {
171171
const getStateMachineArnStub = sinon
172172
.stub(serverlessStepFunctions, 'getStateMachineArn').returns(BbPromise.resolve());
@@ -175,7 +175,7 @@ describe('ServerlessStepFunctions', () => {
175175
const describeExecutionStub = sinon
176176
.stub(serverlessStepFunctions, 'describeExecution').returns(BbPromise.resolve());
177177

178-
return serverlessStepFunctions.invoke()
178+
return serverlessStepFunctions.stateMachineInvoke()
179179
.then(() => {
180180
expect(getStateMachineArnStub.calledOnce).to.be.equal(true);
181181
expect(startExecutionStub.calledAfter(getStateMachineArnStub)).to.be.equal(true);

0 commit comments

Comments
 (0)