-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1467 from NASA-AMMOS/feat/pending-hasura-events
Include Pending Events in Event Log
- Loading branch information
Showing
12 changed files
with
199 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
deployment/hasura/migrations/Aerie/7_pending_hasura_events/down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
drop view hasura.refresh_resource_type_logs; | ||
drop view hasura.refresh_model_parameter_logs; | ||
drop view hasura.refresh_activity_type_logs; | ||
drop function hasura.get_event_logs(_trigger_name text); | ||
|
||
create function hasura.get_event_logs(_trigger_name text) | ||
returns table ( | ||
model_id int, | ||
model_name text, | ||
model_version text, | ||
triggering_user text, | ||
delivered boolean, | ||
success boolean, | ||
tries int, | ||
created_at timestamp, | ||
next_retry_at timestamp, | ||
status int, | ||
error json, | ||
error_message text, | ||
error_type text | ||
) | ||
stable | ||
security invoker | ||
language plpgsql as $$ | ||
begin | ||
return query ( | ||
select | ||
(el.payload->'data'->'new'->>'id')::int as model_id, | ||
el.payload->'data'->'new'->>'name' as model_name, | ||
el.payload->'data'->'new'->>'version' as model_version, | ||
el.payload->'session_variables'->>'x-hasura-user-id' as triggering_user, | ||
el.delivered, | ||
eil.status is not distinct from 200 as success, -- is not distinct from to catch `null` | ||
el.tries, | ||
el.created_at, | ||
el.next_retry_at, | ||
eil.status, | ||
eil.response -> 'data'-> 'message' as error, | ||
eil.response -> 'data'-> 'message'->>'message' as error_message, | ||
eil.response -> 'data'-> 'message'->>'type' as error_type | ||
from hdb_catalog.event_log el | ||
join hdb_catalog.event_invocation_logs eil on el.id = eil.event_id | ||
where trigger_name = _trigger_name); | ||
end; | ||
$$; | ||
comment on function hasura.get_event_logs(_trigger_name text) is e'' | ||
'Get the logs for every run of a Hasura event with the specified trigger name.'; | ||
|
||
create view hasura.refresh_activity_type_logs as | ||
select * from hasura.get_event_logs('refreshActivityTypes'); | ||
comment on view hasura.refresh_activity_type_logs is e'' | ||
'View containing logs for every run of the Hasura event `refreshActivityTypes`.'; | ||
|
||
create view hasura.refresh_model_parameter_logs as | ||
select * from hasura.get_event_logs('refreshModelParameters'); | ||
comment on view hasura.refresh_model_parameter_logs is e'' | ||
'View containing logs for every run of the Hasura event `refreshModelParameters`.'; | ||
|
||
create view hasura.refresh_resource_type_logs as | ||
select * from hasura.get_event_logs('refreshResourceTypes'); | ||
comment on view hasura.refresh_resource_type_logs is e'' | ||
'View containing logs for every run of the Hasura event `refreshResourceTypes`.'; | ||
|
||
|
||
call migrations.mark_migration_rolled_back('7') |
68 changes: 68 additions & 0 deletions
68
deployment/hasura/migrations/Aerie/7_pending_hasura_events/up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
drop view hasura.refresh_resource_type_logs; | ||
drop view hasura.refresh_model_parameter_logs; | ||
drop view hasura.refresh_activity_type_logs; | ||
drop function hasura.get_event_logs(_trigger_name text); | ||
|
||
create function hasura.get_event_logs(_trigger_name text) | ||
returns table ( | ||
model_id int, | ||
model_name text, | ||
model_version text, | ||
triggering_user text, | ||
pending boolean, | ||
delivered boolean, | ||
success boolean, | ||
tries int, | ||
created_at timestamp, | ||
next_retry_at timestamp, | ||
status int, | ||
error json, | ||
error_message text, | ||
error_type text | ||
) | ||
stable | ||
security invoker | ||
language plpgsql as $$ | ||
begin | ||
return query ( | ||
select | ||
(el.payload->'data'->'new'->>'id')::int as model_id, | ||
el.payload->'data'->'new'->>'name' as model_name, | ||
el.payload->'data'->'new'->>'version' as model_version, | ||
el.payload->'session_variables'->>'x-hasura-user-id' as triggering_user, | ||
eil.id is null as pending, | ||
el.delivered, | ||
eil.status is not distinct from 200 as success, -- is not distinct from to catch `null` | ||
el.tries, | ||
el.created_at, | ||
el.next_retry_at, | ||
eil.status, | ||
eil.response -> 'data'-> 'message' as error, | ||
-- Javalin uses "title" as it's "message" field | ||
coalesce(eil.response -> 'data'-> 'message'->> 'message', | ||
eil.response -> 'data'-> 'message'->> 'title') as error_message, | ||
eil.response -> 'data'-> 'message'->>'type' as error_type | ||
from hdb_catalog.event_log el | ||
left join hdb_catalog.event_invocation_logs eil on el.id = eil.event_id | ||
where trigger_name = _trigger_name); | ||
end; | ||
$$; | ||
comment on function hasura.get_event_logs(_trigger_name text) is e'' | ||
'Get the logs for every run of a Hasura event with the specified trigger name.'; | ||
|
||
create view hasura.refresh_activity_type_logs as | ||
select * from hasura.get_event_logs('refreshActivityTypes'); | ||
comment on view hasura.refresh_activity_type_logs is e'' | ||
'View containing logs for every run of the Hasura event `refreshActivityTypes`.'; | ||
|
||
create view hasura.refresh_model_parameter_logs as | ||
select * from hasura.get_event_logs('refreshModelParameters'); | ||
comment on view hasura.refresh_model_parameter_logs is e'' | ||
'View containing logs for every run of the Hasura event `refreshModelParameters`.'; | ||
|
||
create view hasura.refresh_resource_type_logs as | ||
select * from hasura.get_event_logs('refreshResourceTypes'); | ||
comment on view hasura.refresh_resource_type_logs is e'' | ||
'View containing logs for every run of the Hasura event `refreshResourceTypes`.'; | ||
|
||
call migrations.mark_migration_applied('7') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.