-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharchive_event.py
More file actions
141 lines (124 loc) · 3.97 KB
/
Copy patharchive_event.py
File metadata and controls
141 lines (124 loc) · 3.97 KB
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
141
import boto3
import json
import logging
from botocore.exceptions import ClientError
import stackref.settings as settings
from stackref.active_event_update import unset_active_event
from stackref.archive_teams import archive_teams
from stackref.settings import return_error
from stackref.cache_functions import incr_key_prefix
from stackref.tator_notify import tator_notify
from stackref.unassign_cloud_accounts import unassign_cloud_accounts
logging.basicConfig(level=logging.ERROR)
log = logging.getLogger(__name__)
settings.logging_config()
log.setLevel(settings.log_level)
'''
archive_event
Archive an Event and return event_uuid and status
'''
def archive_event(payload_json):
log.info(":: archive_event")
organization_uuid = str(payload_json['event']['organization_uuid'])
event_uuid = str(payload_json['event']['event_uuid'])
try:
unset_active_event(event_uuid)
except Exception as error:
log.error(f'>> archive_event: {error}')
raise error
try:
archive_teams(event_uuid)
except Exception as error:
log.error(f'>> archive_event: {error}')
raise error
sql_statement = ("""
-- Archive the Event
UPDATE
sr.event
SET
event_status_id = (
SELECT
event_status_id
FROM
sr.event_status
WHERE
event_status_name = 'Archived'
),
ts_modified = NOW()
WHERE
organization_uuid = %(organization_uuid)s::UUID
AND event_uuid = %(event_uuid)s::UUID;
""")
sql_parameters = {
'event_uuid': event_uuid,
'organization_uuid': organization_uuid
}
log.debug(sql_statement)
try:
with settings.db_conn() as db_conn:
with db_conn.cursor() as cur:
cur.execute(sql_statement, sql_parameters)
except Exception as error:
log.error(f">> archive_event: {error}")
return return_error(503, error)
try:
incr_key_prefix('kanban_item')
incr_key_prefix('team_score_item')
incr_key_prefix('team_member_role_member')
incr_key_prefix('team_member')
incr_key_prefix('team_codecommit')
incr_key_prefix('team')
incr_key_prefix('participant')
incr_key_prefix('event')
except:
log.error('>> incr_key_prefix')
# Unassign all cloud accounts for the event
try:
unassign_cloud_accounts(event_uuid)
except Exception as error:
log.error(f'>> archive_event: {error}')
# Delete the event kickoffs
try:
delete_kickoff(event_uuid)
except Exception as error:
log.error(f'>> archive_event: {error}')
# Send Tator command to update UI
try:
tator_message = {
"command": "initializeOrgEvents",
"type": "command"
}
tator_notify(tator_message, str(payload_json['event']['organization_uuid']))
except Exception as error:
log.error(f'>> archive_event: {error}')
response_payload = {
'status_code': 200,
'event_uuid': str(event_uuid)
}
response_body = json.dumps(response_payload)
log.info(response_body)
return {
'statusCode': 200,
'headers': {
'Content-Type': 'application/json'
},
'body': response_body
}
'''
delete_kickoff
Delete any set Kickoff events for event_uuid
'''
def delete_kickoff(event_uuid):
log.info(":: delete_kickoff")
scheduler_client = boto3.client('scheduler')
try:
response = scheduler_client.delete_schedule_group(
Name=f'sr_event_{event_uuid}'
)
log.debug(f':: delete_kickoff: {response}')
except ClientError as error:
if error.response['Error']['Code'] == 'ResourceNotFoundException':
log.warning(f'>> delete_kickoff: {error}')
else:
log.error(f'>> delete_kickoff: {error}')
raise error