-
Notifications
You must be signed in to change notification settings - Fork 0
/
workflow.yaml
121 lines (119 loc) · 3.94 KB
/
workflow.yaml
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
main:
params: [args]
steps:
- initial:
assign:
- type: "מסחרי"
- project_id: ${sys.get_env("GOOGLE_CLOUD_PROJECT_ID")}
- dataset_id: "`yarel-playground.cars.cars_history`"
next: extract_license_plate_id
- extract_license_plate_id:
call: http.get
args:
url: https://licenseplate-a3d4cv5haa-ez.a.run.app
headers:
Content-Type: "text/plain"
query:
bucket_name: ${args.car_photos_bucket_name}
img_file_name: ${args.car_photo_file_name}
auth:
type: OIDC
result: car_license_plate
next: log_license_plate
- log_license_plate:
call: sys.log
args:
text: ${car_license_plate.body}
severity: "INFO" # Optional
next: check_if_found_license_plate
- check_if_found_license_plate:
switch:
- condition: ${car_license_plate.body == ""}
steps:
- plate_failure:
call: failure
args:
to_email: ${args.to_email}
next: end
next: get_message
- get_message:
try:
call: http.get
args:
url: https://data.gov.il/api/3/action/datastore_search
headers:
Content-Type: "text/plain"
query:
resource_id: "053cea08-09bc-40ec-8f7a-156f0677aff3"
q: ${car_license_plate.body}
result: car_record
retry: ${http.default_retry}
except:
steps:
- http_failure:
call: failure
args:
to_email: ${args.to_email}
next: end
next: details
- details:
try:
assign:
- baalut: ${car_record.body.result.records[0].baalut}
- brand: ${car_record.body.result.records[0].tozeret_nm}
- model: ${car_record.body.result.records[0].kinuy_mishari}
- year: ${car_record.body.result.records[0].shnat_yitzur}
- front_tire: ${car_record.body.result.records[0].zmig_kidmi}
- back_tire: ${car_record.body.result.records[0].zmig_ahori}
except:
steps:
- details_failure:
call: failure
args:
to_email: ${args.to_email}
next: end
next: vehicle_type
- vehicle_type:
switch:
- condition: ${baalut == "פרטי"}
next: private
- private:
assign:
- type: "פרטי"
next: insert_data
- insert_data:
call: googleapis.bigquery.v2.jobs.query
args:
projectId: ${project_id}
body:
useLegacySql: false
query: ${"INSERT "+dataset_id+" (model, type, id, brand, year) VALUES ('"+string(model)+"', '"+string(type)+"', '" + car_license_plate.body + "', '" + text.replace_all(string(brand), "'", "") + "', '" + string(year) + "')"}
- call_reciept:
call: http.post
args:
url: https://notification-a3d4cv5haa-ez.a.run.app
body:
VehicleID: ${car_license_plate.body}
Brand: ${brand}
Model: ${model}
Year: ${string(year)}
FrontTire: ${front_tire}
BackTire: ${back_tire}
ToEmail: ${args.to_email}
auth:
type: OIDC
next: end
- return_value:
return: ${"Vehicle type is "+string(type)+", brand is "+string(brand)+", model is "+string(model)+", year is "+string(year)}
failure:
params: [to_email]
steps:
- send_failure_email:
call: http.post
args:
url: https://notification-a3d4cv5haa-ez.a.run.app
body:
ToEmail: ${to_email}
auth:
type: OIDC
next: end