-
Notifications
You must be signed in to change notification settings - Fork 0
/
02-pipelines-and-statuses.cfc
140 lines (126 loc) · 3.9 KB
/
02-pipelines-and-statuses.cfc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/**
* This exercise goes over:
* + Passing futures to pipelines
* + The differences between `then` (`thenAccept` and `thenApply`) and `thenRun`
* + The different states of a Future
*
* You can run this exercise from the root in CommandBox by running:
* `task run exercises/02-pipelines-and-statuses.cfc`
*
* You can use the `print` helper provided by CommandBox to log messages.
* (Use `print.line( "message" ).toConsole()` if you're not familiar with it.)
* Make sure to end with `.toConsole()` so your message is flushed
* to the console the moment it is printed.
*/
component extends="../BaseTask" {
variables.secretKey = "My6406GWQxqDkMthMhQ3NA==";
/**
* Create a future that computes a strong hash of a string.
* (Use the `strongHash( string )` function to compute the hash.)
* When the task is complete, asynchronously output the hash to the console.
*/
function partOne(){
return;
}
/**
* Create a future that computes a strong hash of a string.
* (Use the `strongHash( string )` function to compute the hash.)
* Then, encrypt the hash using the `strongEncrypt( string )` function.
* Finally, output that value to the console asynchronously.
*/
function partTwo(){
return;
}
/**
* Create a future that computes a strong hash of a string.
* (Use the `strongHash( string )` function to compute the hash.)
* Then, encrypt the hash using the `strongEncrypt( string )` function.
* Then, send that string to a remote server using the `syncToReliableServer( string )` function.
*
* While that code is running, display a waiting message that updates every second
* until the pipeline has completed successfully. For example:
* ```sh
* > Starting the process to securely hash, encrypt, and store your password.
* > Please wait...
* > Please wait...
* > Please wait...
* > Please wait...
* > Operation completed successfully.
* ```
*/
function partThree(){
return;
}
/**
* Create a future that computes a strong hash of a string.
* (Use the `strongHash( string )` function to compute the hash.)
* Then, encrypt the hash using the `strongEncrypt( string )` function.
* Then, send that string to a remote server using the `syncToFlakyServer( string )` function.
*
* While that code is running, display a waiting message that updates every second
* until the pipeline has completed successfully. For example:
* ```sh
* > Starting the process to securely hash, encrypt, and store your password.
* > Please wait...
* > Please wait...
* > Please wait...
* > Please wait...
* > Operation completed successfully.
* ```
*
* Make sure to account for the error case:
* * ```sh
* > Starting the process to securely hash, encrypt, and store your password.
* > Please wait...
* > Please wait...
* > Operation failed. Please try again later.
* ```
*/
function partFour(){
return;
}
function run(){
print.blueLine( "Running all `02-pipelines-and-statuses` exercises" ).toConsole();
print
.yellowLine( "Press Ctrl-C to exit" )
.line()
.toConsole();
partOne();
partTwo();
partThree();
partFour();
while ( true ) {
if ( !isNull( checkInterrupted() ) ) {
return;
}
sleep( 100 );
}
}
private string function strongHash( required any value ){
return getInstance( "@BCrypt" ).hashPassword( arguments.value, 15 );
}
private string function strongEncrypt( required any value ){
return encrypt(
arguments.value,
variables.secretKey,
"BLOWFISH",
"base64"
);
}
private boolean function syncToReliableServer( required any value ){
sleep( randRange( 4000, 8000 ) );
return true;
}
private boolean function syncToFlakyServer( required any value ){
if ( randRange( 1, 2 ) == 1 ) {
sleep( randRange( 2000, 4000 ) );
throw( "Uh oh...server is being flaky" );
}
sleep( randRange( 3000, 6000 ) );
return true;
}
function init(){
super.init();
loadModule( "../modules/bCrypt" );
}
}