这是indexloc提供的服务,不要输入任何密码
Skip to content
115 changes: 71 additions & 44 deletions console/src/components/Services/EventTrigger/EventActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { getEventTriggersQuery } from './utils';

import { CLI_CONSOLE_MODE, SERVER_CONSOLE_MODE } from '../../../constants';
import { REQUEST_COMPLETE, REQUEST_ONGOING } from './Modify/Actions';
import { IMPROVED_EVENT_FETCH_QUERY } from '../../../helpers/versionUtils';

const SET_TRIGGER = 'Event/SET_TRIGGER';
const LOAD_TRIGGER_LIST = 'Event/LOAD_TRIGGER_LIST';
Expand Down Expand Up @@ -91,32 +92,41 @@ const loadTriggers = triggerNames => (dispatch, getState) => {

const loadPendingEvents = () => (dispatch, getState) => {
const url = Endpoints.getSchema;
const body = {
type: 'select',
args: {
table: {
name: 'event_triggers',
schema: 'hdb_catalog',
},
columns: [
'*',
{
name: 'events',
columns: [
'*',
{ name: 'logs', columns: ['*'], order_by: ['-created_at'] },
],
where: { delivered: false, error: false, tries: 0 },
order_by: ['-created_at'],
limit: 10,
},
],
},
};

if (
globals.featuresCompatibility &&
globals.featuresCompatibility[IMPROVED_EVENT_FETCH_QUERY]
) {
body.args.columns[1].where.archived = false;
}

const options = {
credentials: globalCookiePolicy,
method: 'POST',
headers: dataHeaders(getState),
body: JSON.stringify({
type: 'select',
args: {
table: {
name: 'event_triggers',
schema: 'hdb_catalog',
},
columns: [
'*',
{
name: 'events',
columns: [
'*',
{ name: 'logs', columns: ['*'], order_by: ['-created_at'] },
],
where: { delivered: false, error: false, tries: 0 },
order_by: ['-created_at'],
limit: 10,
},
],
},
}),
body: JSON.stringify(body),
};
return dispatch(requestAction(url, options)).then(
data => {
Expand All @@ -130,32 +140,41 @@ const loadPendingEvents = () => (dispatch, getState) => {

const loadRunningEvents = () => (dispatch, getState) => {
const url = Endpoints.getSchema;
const body = {
type: 'select',
args: {
table: {
name: 'event_triggers',
schema: 'hdb_catalog',
},
columns: [
'*',
{
name: 'events',
columns: [
'*',
{ name: 'logs', columns: ['*'], order_by: ['-created_at'] },
],
where: { delivered: false, error: false, tries: { $gt: 0 } },
order_by: ['-created_at'],
limit: 10,
},
],
},
};

if (
globals.featuresCompatibility &&
globals.featuresCompatibility[IMPROVED_EVENT_FETCH_QUERY]
) {
body.args.columns[1].where.archived = false;
}

const options = {
credentials: globalCookiePolicy,
method: 'POST',
headers: dataHeaders(getState),
body: JSON.stringify({
type: 'select',
args: {
table: {
name: 'event_triggers',
schema: 'hdb_catalog',
},
columns: [
'*',
{
name: 'events',
columns: [
'*',
{ name: 'logs', columns: ['*'], order_by: ['-created_at'] },
],
where: { delivered: false, error: false, tries: { $gt: 0 } },
order_by: ['-created_at'],
limit: 10,
},
],
},
}),
body: JSON.stringify(body),
};
return dispatch(requestAction(url, options)).then(
data => {
Expand Down Expand Up @@ -214,6 +233,14 @@ const loadEventLogs = triggerName => (dispatch, getState) => {
},
],
};

if (
globals.featuresCompatibility &&
globals.featuresCompatibility[IMPROVED_EVENT_FETCH_QUERY]
) {
body.args[0].args.where.event.archived = false;
}

const logOptions = {
credentials: globalCookiePolicy,
method: 'POST',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import requestAction from '../../../../utils/requestAction';
import pendingFilterReducer from './FilterActions';
import { findTableFromRel } from '../utils';
import dataHeaders from '../Common/Headers';
import globals from '../../../../Globals';
import { IMPROVED_EVENT_FETCH_QUERY } from '../../../../helpers/versionUtils';

/* ****************** View actions *************/
const V_SET_DEFAULTS = 'PendingEvents/V_SET_DEFAULTS';
Expand Down Expand Up @@ -66,6 +68,17 @@ const vMakeRequest = () => {
};
}

if (
globals.featuresCompatibility &&
globals.featuresCompatibility[IMPROVED_EVENT_FETCH_QUERY]
) {
if (currentQuery.columns[1]) {
currentQuery.columns[1].where = currentQuery.columns[1].where || {};
currentQuery.columns[1].where.archived = false;
}
countQuery.where.archived = false;
}

// order_by for relationship
const currentOrderBy = state.triggers.view.query.order_by;
if (currentOrderBy) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
} from '../../Common/Notification';
import dataHeaders from '../Common/Headers';
import { getConfirmation } from '../../../Common/utils/jsUtils';
import globals from '../../../../Globals';
import { IMPROVED_EVENT_FETCH_QUERY } from '../../../../helpers/versionUtils';

/* ****************** View actions *************/
const V_SET_DEFAULTS = 'ProcessedEvents/V_SET_DEFAULTS';
Expand Down Expand Up @@ -80,6 +82,17 @@ const vMakeRequest = () => {
};
}

if (
globals.featuresCompatibility &&
globals.featuresCompatibility[IMPROVED_EVENT_FETCH_QUERY]
) {
if (currentQuery.columns[1]) {
currentQuery.columns[1].where = currentQuery.columns[1].where || {};
currentQuery.columns[1].where.archived = false;
}
countQuery.where.archived = false;
}

// order_by for relationship
const currentOrderBy = state.triggers.view.query.order_by;
if (currentOrderBy) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import requestAction from 'utils/requestAction';
import pendingFilterReducer from './FilterActions';
import { findTableFromRel } from '../utils';
import dataHeaders from '../Common/Headers';
import globals from '../../../../Globals';
import { IMPROVED_EVENT_FETCH_QUERY } from '../../../../helpers/versionUtils';

/* ****************** View actions *************/
const V_SET_DEFAULTS = 'RunningEvents/V_SET_DEFAULTS';
Expand Down Expand Up @@ -72,6 +74,17 @@ const vMakeRequest = () => {
};
}

if (
globals.featuresCompatibility &&
globals.featuresCompatibility[IMPROVED_EVENT_FETCH_QUERY]
) {
if (currentQuery.columns[1]) {
currentQuery.columns[1].where = currentQuery.columns[1].where || {};
currentQuery.columns[1].where.archived = false;
}
countQuery.where.archived = false;
}

// order_by for relationship
const currentOrderBy = state.triggers.view.query.order_by;
if (currentOrderBy) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { defaultLogState } from '../EventState';
import Endpoints, { globalCookiePolicy } from '../../../../Endpoints';
import requestAction from 'utils/requestAction';
import dataHeaders from '../Common/Headers';
import globals from '../../../../Globals';
import { IMPROVED_EVENT_FETCH_QUERY } from '../../../../helpers/versionUtils';

/* ****************** View actions *************/
const V_SET_DEFAULTS = 'StreamingLogs/V_SET_DEFAULTS';
Expand Down Expand Up @@ -42,6 +44,14 @@ const vMakeRequest = triggerName => {

currentQuery.where = { event: { trigger_name: triggerName } };

if (
globals.featuresCompatibility &&
globals.featuresCompatibility[IMPROVED_EVENT_FETCH_QUERY]
) {
currentQuery.where.event.archived = false;
countQuery.where.event.archived = false;
}

// order_by for relationship
currentQuery.order_by = ['-created_at'];

Expand Down Expand Up @@ -112,6 +122,14 @@ const loadNewerEvents = (latestTimestamp, triggerName) => {
created_at: { $gt: latestTimestamp },
};

if (
globals.featuresCompatibility &&
globals.featuresCompatibility[IMPROVED_EVENT_FETCH_QUERY]
) {
currentQuery.where.event.archived = false;
countQuery.where.event.archived = false;
}

// order_by for relationship
currentQuery.order_by = ['-created_at'];

Expand Down Expand Up @@ -202,6 +220,14 @@ const loadOlderEvents = (oldestTimestamp, triggerName) => {
created_at: { $lt: oldestTimestamp },
};

if (
globals.featuresCompatibility &&
globals.featuresCompatibility[IMPROVED_EVENT_FETCH_QUERY]
) {
currentQuery.where.event.archived = false;
countQuery.where.event.archived = false;
}

// order_by for relationship
currentQuery.order_by = ['-created_at'];

Expand Down
2 changes: 2 additions & 0 deletions console/src/helpers/versionUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const TABLE_ENUMS_SUPPORT = 'tableEnumsSupport';
export const EXISTS_PERMISSION_SUPPORT = 'existsPermissionSupport';
export const CUSTOM_GRAPHQL_FIELDS_SUPPORT = 'customGraphQLFieldsSupport';
export const COMPUTED_FIELDS_SUPPORT = 'computedFieldsSupport';
export const IMPROVED_EVENT_FETCH_QUERY = 'improvedEventFetchQuery';

// list of feature launch versions
const featureLaunchVersions = {
Expand All @@ -21,6 +22,7 @@ const featureLaunchVersions = {
[EXISTS_PERMISSION_SUPPORT]: 'v1.0.0-beta.7',
[CUSTOM_GRAPHQL_FIELDS_SUPPORT]: 'v1.0.0-beta.8',
[COMPUTED_FIELDS_SUPPORT]: 'v1.0.0-beta.8',
[IMPROVED_EVENT_FETCH_QUERY]: 'v1.0.0-beta.10',
};

export const checkValidServerVersion = version => {
Expand Down
5 changes: 2 additions & 3 deletions server/src-lib/Hasura/Events/Lib.hs
Original file line number Diff line number Diff line change
Expand Up @@ -441,10 +441,9 @@ fetchEvents =
SET locked = 't'
WHERE id IN ( SELECT l.id
FROM hdb_catalog.event_log l
JOIN hdb_catalog.event_triggers e
ON (l.trigger_name = e.name)
WHERE l.delivered ='f' and l.error = 'f' and l.locked = 'f'
WHERE l.delivered = 'f' and l.error = 'f' and l.locked = 'f'
and (l.next_retry_at is NULL or l.next_retry_at <= now())
and l.archived = 'f'
FOR UPDATE SKIP LOCKED
LIMIT 100 )
RETURNING id, schema_name, table_name, trigger_name, payload::json, tries, created_at
Expand Down
13 changes: 11 additions & 2 deletions server/src-lib/Hasura/RQL/DDL/EventTrigger.hs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ addEventTriggerToCatalog qt allCols strfyNum etc = do
INSERT into hdb_catalog.event_triggers
(name, type, schema_name, table_name, configuration)
VALUES ($1, 'table', $2, $3, $4)
|] (name, sn, tn, Q.AltJ $ toJSON etc) True
|] (name, sn, tn, Q.AltJ $ toJSON etc) False

mkAllTriggersQ name qt allCols strfyNum fullspec
where
Expand All @@ -148,8 +148,17 @@ delEventTriggerFromCatalog trn = do
DELETE FROM
hdb_catalog.event_triggers
WHERE name = $1
|] (Identity trn) True
|] (Identity trn) False
delTriggerQ trn
archiveEvents trn

archiveEvents:: TriggerName -> Q.TxE QErr ()
archiveEvents trn = do
Q.unitQE defaultTxErrorHandler [Q.sql|
UPDATE hdb_catalog.event_log
SET archived = 't'
WHERE trigger_name = $1
|] (Identity trn) False

updateEventTriggerToCatalog
:: QualifiedTable
Expand Down
2 changes: 1 addition & 1 deletion server/src-lib/Hasura/Server/Migrate/Version.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Hasura.Prelude
import qualified Data.Text as T

latestCatalogVersion :: Integer
latestCatalogVersion = 26
latestCatalogVersion = 27

latestCatalogVersionString :: T.Text
latestCatalogVersionString = T.pack $ show latestCatalogVersion
4 changes: 3 additions & 1 deletion server/src-rsr/initialise.sql
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,13 @@ CREATE TABLE hdb_catalog.event_log
tries INTEGER NOT NULL DEFAULT 0,
created_at TIMESTAMP DEFAULT NOW(),
locked BOOLEAN NOT NULL DEFAULT FALSE,
next_retry_at TIMESTAMP
next_retry_at TIMESTAMP,
archived BOOLEAN NOT NULL DEFAULT FALSE
);

CREATE INDEX ON hdb_catalog.event_log (trigger_name);
CREATE INDEX ON hdb_catalog.event_log (locked);
CREATE INDEX ON hdb_catalog.event_log (delivered);

CREATE TABLE hdb_catalog.event_invocation_logs
(
Expand Down
9 changes: 9 additions & 0 deletions server/src-rsr/migrations/26_to_27.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ALTER TABLE hdb_catalog.event_log
ADD COLUMN archived BOOLEAN NOT NULL DEFAULT FALSE;

UPDATE hdb_catalog.event_log
SET archived = 't'
WHERE
trigger_name NOT IN (SELECT name from hdb_catalog.event_triggers);

CREATE INDEX ON hdb_catalog.event_log (delivered);