add wait until syntax
This commit is contained in:
parent
931a2a5de7
commit
33a75680ee
7 changed files with 73 additions and 12 deletions
|
|
@ -18,6 +18,8 @@ pipeline:
|
|||
|
||||
- async: git-count
|
||||
|
||||
- wait-until-string: <!state.git-count> != complete
|
||||
|
||||
- while:
|
||||
condition-int: <!property.git-count> == null
|
||||
on-do:
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@ import 'package:yaml/yaml.dart';
|
|||
|
||||
enum BuildType { jenkins, test, file }
|
||||
|
||||
enum CommandState { ready, progress, complete }
|
||||
|
||||
class Application {
|
||||
Application._privateConstructor();
|
||||
static final Application _instance = Application._privateConstructor();
|
||||
|
|
@ -28,6 +30,7 @@ class Application {
|
|||
|
||||
DataJenkins? jenkinsData;
|
||||
Map<String, dynamic> property = {};
|
||||
Map<String, CommandState> commandStates = {};
|
||||
Map<String, DataCommand> dataCommandMap = {};
|
||||
late Pipeline pipeline;
|
||||
|
||||
|
|
@ -111,6 +114,10 @@ class Application {
|
|||
return map;
|
||||
}
|
||||
|
||||
void updateCommandState(String target, CommandState state) {
|
||||
commandStates[target] = state;
|
||||
}
|
||||
|
||||
Future printBuildStep(String name, Color? color) async {
|
||||
var message =
|
||||
'''************************************************************************************
|
||||
|
|
|
|||
|
|
@ -114,6 +114,17 @@ abstract class Command {
|
|||
}
|
||||
}
|
||||
|
||||
if (value.startsWith('state.')) {
|
||||
var map = Application.instance.commandStates;
|
||||
var param = value.replaceFirst('state.', '');
|
||||
if (map.containsKey(param)) {
|
||||
data = map[param].toString().replaceAll('CommandState.', '');
|
||||
} else {
|
||||
data = null;
|
||||
}
|
||||
setted = true;
|
||||
}
|
||||
|
||||
if (!setted) {
|
||||
throw Exception(
|
||||
'Command.getTagValue: "$value" is not defined in property.');
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import 'package:dart_framework/utils/system_util.dart';
|
||||
import 'package:oto_cli/oto/pipeline/pipeline_exe.dart';
|
||||
import 'package:oto_cli/oto/pipeline/pipeline_if.dart';
|
||||
import 'package:oto_cli/oto/pipeline/pipeline_wait_until.dart';
|
||||
import 'package:oto_cli/oto/pipeline/pipeline_while.dart';
|
||||
|
||||
class Pipeline {
|
||||
|
|
@ -9,8 +10,10 @@ class Pipeline {
|
|||
'async': () => PipelineAsync(),
|
||||
'if': () => PipelineIf(),
|
||||
'while': () => PipelineWhile(),
|
||||
/*'wait-until': () => PipelineWaitUntil(),
|
||||
'switch': () => PipelineSwitch(),*/
|
||||
'wait-until-int': () => PipelineWaitUntil('int'),
|
||||
'wait-until-double': () => PipelineWaitUntil('double'),
|
||||
'wait-until-string': () => PipelineWaitUntil('string'),
|
||||
/*'switch': () => PipelineSwitch(),*/
|
||||
};
|
||||
|
||||
//pipeline validate & initialize
|
||||
|
|
|
|||
|
|
@ -40,11 +40,10 @@ abstract class PiplineCondition extends PipelineExecutor {
|
|||
|
||||
Future printCondition(String syntax, String condition, String postfix,
|
||||
ConditionCheckResult result) async {
|
||||
var quotesPre = Platform.isWindows ? '^"' : '';
|
||||
var quotesLast = Platform.isWindows ? '"' : '';
|
||||
var printStr =
|
||||
'$quotesPre[$syntax] ($condition) / (${result.conditionValue}) : ${result.result} ===> $postfix$quotesLast';
|
||||
await CLI.println(printStr, color: Color.magentaStrong);
|
||||
await CLI.println('[Pipeline-$syntax]', color: Color.magentaStrong);
|
||||
print(
|
||||
' - Condition: ($condition)\n - Values: (${result.conditionValue})\n - Result: ${result.result} ===> $postfix');
|
||||
|
||||
return simpleFuture;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,21 +20,22 @@ abstract class PipelineExecutor {
|
|||
}
|
||||
|
||||
class PipelineExe extends PipelineExecutor {
|
||||
late String targetCommandID;
|
||||
late String commandID;
|
||||
@override
|
||||
PipelineValidateResult initialize(Map<String, dynamic> set) {
|
||||
var result = PipelineValidateResult();
|
||||
targetCommandID = set.values.first as String;
|
||||
if (!Application.instance.dataCommandMap.containsKey(targetCommandID)) {
|
||||
commandID = set.values.first as String;
|
||||
if (!Application.instance.dataCommandMap.containsKey(commandID)) {
|
||||
result.enable = false;
|
||||
result.message =
|
||||
'The "$targetCommandID" command does not exist in the command list.';
|
||||
'The "$commandID" command does not exist in the command list.';
|
||||
}
|
||||
updateState(CommandState.ready);
|
||||
return result;
|
||||
}
|
||||
|
||||
Future<DataCommand> get commandData async {
|
||||
var commandData = Application.instance.dataCommandMap[targetCommandID]!;
|
||||
var commandData = Application.instance.dataCommandMap[commandID]!;
|
||||
await Application.instance
|
||||
.printBuildStep('Phase Start: ${commandData.name}', Color.green);
|
||||
return dataFutrue(commandData);
|
||||
|
|
@ -46,20 +47,28 @@ class PipelineExe extends PipelineExecutor {
|
|||
// var time =
|
||||
// '${now.minute.toString().padLeft(2)}:${now.second.toString().padLeft(2)}:${now.millisecond.toString().padLeft(2)}';
|
||||
// print('==================> [$time] Execute: $targetCommandID');
|
||||
updateState(CommandState.progress);
|
||||
var data = await commandData;
|
||||
await Command.byType(data.command).execute(data);
|
||||
updateState(CommandState.complete);
|
||||
return simpleFuture;
|
||||
}
|
||||
|
||||
void updateState(CommandState state) {
|
||||
Application.instance.updateCommandState(commandID, state);
|
||||
}
|
||||
}
|
||||
|
||||
class PipelineAsync extends PipelineExe {
|
||||
@override
|
||||
Future execute() async {
|
||||
updateState(CommandState.progress);
|
||||
executeAsync(await commandData);
|
||||
return simpleFuture;
|
||||
}
|
||||
|
||||
void executeAsync(DataCommand data) async {
|
||||
await Command.byType(data.command).execute(data);
|
||||
updateState(CommandState.complete);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
30
lib/oto/pipeline/pipeline_wait_until.dart
Normal file
30
lib/oto/pipeline/pipeline_wait_until.dart
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import 'package:dart_framework/utils/system_util.dart';
|
||||
import 'package:oto_cli/oto/data/pipeline_data.dart';
|
||||
import 'package:oto_cli/oto/pipeline/pipeline.dart';
|
||||
import 'package:oto_cli/oto/pipeline/pipeline_condition.dart';
|
||||
|
||||
class PipelineWaitUntil extends PiplineCondition {
|
||||
PipelineWaitUntil(String type) {
|
||||
data = DataCondition();
|
||||
data.type = type;
|
||||
}
|
||||
|
||||
@override
|
||||
PipelineValidateResult initialize(Map<String, dynamic> set) {
|
||||
data.condition = set.values.first as String;
|
||||
return super.initialize(set);
|
||||
}
|
||||
|
||||
@override
|
||||
Future execute() async {
|
||||
var condition = data.condition!;
|
||||
var result = checkCondition(condition);
|
||||
await printCondition('Wait-Unint', condition, 'Start wait.', result);
|
||||
while (result.result) {
|
||||
await Future.delayed(const Duration(milliseconds: 500));
|
||||
result = checkCondition(data.condition!);
|
||||
}
|
||||
await printCondition('Wait-Unint', condition, 'Loop escape.', result);
|
||||
return simpleFuture;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue