4
4
using System . Threading . Tasks ;
5
5
using Cleipnir . ResilientFunctions ;
6
6
using Cleipnir . ResilientFunctions . Domain ;
7
- using Cleipnir . ResilientFunctions . Helpers ;
8
7
using Cleipnir . ResilientFunctions . MariaDb ;
9
8
using Cleipnir . ResilientFunctions . PostgreSQL ;
10
9
using Cleipnir . ResilientFunctions . SqlServer ;
@@ -16,30 +15,35 @@ public static class Example
16
15
{
17
16
public static async Task Perform ( )
18
17
{
19
- var postgresStore = new PostgreSqlFunctionStore ( "Server=localhost;Database=rfunctions;User Id=postgres;Password=Pa55word!; Include Error Detail=true;" ) ;
18
+ const string postgresConnStr = "Server=localhost;Database=cleipnir_samples;User Id=postgres;Password=Pa55word!;Include Error Detail=true;" ;
19
+ await Cleipnir . ResilientFunctions . PostgreSQL . DatabaseHelper . CreateDatabaseIfNotExists ( postgresConnStr ) ;
20
+ var postgresStore = new PostgreSqlFunctionStore ( postgresConnStr ) ;
20
21
await postgresStore . Initialize ( ) ;
21
22
await postgresStore . TruncateTables ( ) ;
22
- var sqlServerStore = new SqlServerFunctionStore ( "Server=localhost;Database=rfunctions;User Id=sa;Password=Pa55word!;Encrypt=True;TrustServerCertificate=True;Max Pool Size=200;" ) ;
23
+
24
+ const string sqlServerConnStr = "Server=localhost;Database=CleipnirSamples;User Id=sa;Password=Pa55word!;Encrypt=True;TrustServerCertificate=True;Max Pool Size=200;" ;
25
+ await Cleipnir . ResilientFunctions . SqlServer . DatabaseHelper . CreateDatabaseIfNotExists ( sqlServerConnStr ) ;
26
+ var sqlServerStore = new SqlServerFunctionStore ( sqlServerConnStr ) ;
23
27
await sqlServerStore . Initialize ( ) ;
24
28
await sqlServerStore . TruncateTables ( ) ;
25
- var mariaDbStore = new MariaDbFunctionStore ( "server=localhost;userid=root;password=Pa55word!;database=rfunctions;AllowPublicKeyRetrieval=True;" ) ;
29
+
30
+ const string mariaDbConnStr = "server=localhost;userid=root;password=Pa55word!;database=cleipnir_samples;AllowPublicKeyRetrieval=True;" ;
31
+ await Cleipnir . ResilientFunctions . MariaDb . DatabaseHelper . CreateDatabaseIfNotExists ( mariaDbConnStr ) ;
32
+ var mariaDbStore = new MariaDbFunctionStore ( mariaDbConnStr ) ;
26
33
await mariaDbStore . Initialize ( ) ;
27
34
await mariaDbStore . TruncateTables ( ) ;
28
35
29
36
Console . WriteLine ( ) ;
30
37
Console . WriteLine ( "Postgres: " ) ;
31
- var postgresTask = Task . Run ( ( ) => Perform ( postgresStore ) ) ;
38
+ await Perform ( postgresStore ) ;
32
39
Console . WriteLine ( ) ;
33
40
Console . WriteLine ( "SqlServer:" ) ;
34
- var sqlServerTask = Task . Run ( ( ) => Perform ( sqlServerStore ) ) ;
41
+ await Perform ( sqlServerStore ) ;
35
42
Console . WriteLine ( ) ;
36
- Console . WriteLine ( "MySql:" ) ;
37
- var mariaDbTask = Task . Run ( ( ) => Perform ( mariaDbStore ) ) ;
38
-
39
- await postgresTask ;
40
- await sqlServerTask ;
41
- await mariaDbTask ;
43
+ Console . WriteLine ( "MariaDB:" ) ;
44
+ await Perform ( mariaDbStore ) ;
42
45
46
+ Console . WriteLine ( ) ;
43
47
Console . WriteLine ( "All completed!" ) ;
44
48
}
45
49
@@ -48,36 +52,23 @@ private static async Task Perform(IFunctionStore store)
48
52
Console . WriteLine ( "Started: " + store . GetType ( ) . Name ) ;
49
53
50
54
await store . Initialize ( ) ;
51
- var functions = new FunctionsRegistry (
52
- store ,
53
- new Settings ( unhandledExceptionHandler : Console . WriteLine , watchdogCheckFrequency : TimeSpan . FromSeconds ( 60 ) , leaseLength : TimeSpan . FromSeconds ( 5 ) )
54
- ) ;
55
+ var registry = new FunctionsRegistry ( store , new Settings ( unhandledExceptionHandler : Console . WriteLine ) ) ;
55
56
56
- var processOrder = functions . RegisterAction < ProcessOrderRequest > (
57
+ var processOrder = registry . RegisterAction < string > (
57
58
"ProcessOrder" ,
58
59
ProcessOrder . Execute
59
60
) ;
60
- ProcessOrders . ProcessOrder ! . Value = processOrder ;
61
- var processOrders = functions . RegisterAction < List < string > > (
61
+ ProcessOrders . ProcessOrder = processOrder ;
62
+ var processOrders = registry . RegisterAction < List < string > > (
62
63
"ProcessOrders" ,
63
64
ProcessOrders . Execute
64
65
) ;
65
- ProcessOrder . MessageWriters = processOrders . MessageWriters ;
66
-
66
+
67
67
var orderIds = Enumerable
68
- . Range ( 0 , 150 )
69
- . Select ( _ => Guid . NewGuid ( ) . ToString ( ) ) //Random.Shared.Next(1000, 9999)
68
+ . Range ( 100 , 150 )
69
+ . Select ( id => $ "MK- { id } " )
70
70
. ToList ( ) ;
71
- await processOrders . Schedule ( "2024-01-27" , orderIds ) ;
72
-
73
- var controlPanel = await processOrders . ControlPanel ( "2024-01-27" ) ;
74
-
75
- await BusyWait . Until ( async ( ) =>
76
- {
77
- await controlPanel ! . Refresh ( ) ;
78
- return controlPanel . Status == Status . Succeeded ;
79
- } , maxWait : TimeSpan . FromSeconds ( 60 ) ) ;
80
71
81
- Console . WriteLine ( "Completed: " + store . GetType ( ) . Name ) ;
72
+ await processOrders . Schedule ( "2024-01-27" , orderIds ) . Completion ( ) ;
82
73
}
83
74
}
0 commit comments