-
Notifications
You must be signed in to change notification settings - Fork 3
/
serviceExample_todeScript.st
104 lines (103 loc) · 3.81 KB
/
serviceExample_todeScript.st
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
[ :topez :objIn :tokens :command :commandNode |
| opts args |
"for help: ./serviceExample -h"
command
getOptsMixedLongShort:
{#('help' $h #'none').
#('task' nil #'optional').
#('poll' nil #'optional').
#('addToQueue' nil #'none').
#('reset' nil #'none').
#('status' nil #'none')}
optionsAndArguments: [ :options :operands |
opts := options.
args := operands ].
opts
at: 'help'
ifAbsent: [
| response taskClass taskInstances |
taskClass := WAGemStoneServiceExampleTask.
taskInstances := UserGlobals
at: #'SERVICE_EXAMPLE_INSTANCES'
ifAbsent: [ UserGlobals at: #'SERVICE_EXAMPLE_INSTANCES' put: Dictionary new ].
opts
at: 'task'
ifPresent: [ :taskId |
| task |
taskId
ifNil: [
response := task := taskClass
valuable:
(WAGemStoneServiceExampleTimeInLondon
url: 'http://www.time.org/zones/Europe/London.php').
taskInstances at: task id put: task ]
ifNotNil: [
System commit. "ensure that we are accessing latest state of task"
response := task := taskInstances at: taskId asNumber ].
opts
at: 'addToQueue'
ifPresent: [ :ignored |
task addToQueue.
System commit "so that service vm can see new queue entry" ].
opts
at: 'poll'
ifPresent: [ :limitArg |
| limit count |
limit := 10.
limitArg ifNotNil: [ limit := limitArg asNumber ].
count := 0.
[
System abort. "so that service vm can see new queue entry"
task hasValue not and: [ count <= limit ] ]
whileTrue: [
(Delay forSeconds: 1) wait.
count := count + 1 ].
System abort.
task hasValue
ifTrue: [ response := task ]
ifFalse: [ response := task -> ('not finished after ' , count printString , ' seconds') ] ] ]
ifAbsent: [
opts
at: 'reset'
ifPresent: [ :ignored |
WAGemStoneServiceExampleVM initialize.
response := taskClass reset.
UserGlobals at: #'SERVICE_EXAMPLE_INSTANCES' put: Dictionary new.
System commit.
topez evaluateCommandString: './serviceVM --restart'.
System abort ].
opts
at: 'status'
ifPresent: [ :ignored |
| dict |
dict := Dictionary new
at: 'queue' put: taskClass queueCollection;
at: 'inProcess' put: taskClass inProcessCollection;
at: 'high water' put: taskClass idHighWater;
at: 'instances' put: taskInstances;
at: 'service loop' put: WAGemStoneServiceExampleVM tasks first;
yourself.
dict edit: topez. "bring up inspector"
response := dict ] ].
response ]
ifPresent: [ :ignored |
TDManPage
viewManPage:
'NAME
serviceExample - serviceExample sript utility template
SYNOPSIS
serviceExample [-h|--help] [--reset] [--status]
serviceExample --task[=<task-id>] [--addToQueue] [--poll[=<poll-limit>]
DESCRIPTION
EXAMPLES
./serviceExample --help
./serviceExample --reset # clear service task queues and counters
# only use reset when service is not
# running
./serviceExample --status # state of service task engine
./serviceExample --task # create a new task
./serviceExample --task=3 # access task #3
./serviceExample --task=3 --addToQueue # schedule task #3 to process next step
./serviceExample --task=3 --poll=10 # poll until task #3 finished step (10 tries)
'
topez: topez ] ]