File: timecheck.sql

package info (click to toggle)
postgis 3.5.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 69,528 kB
  • sloc: ansic: 162,229; sql: 93,970; xml: 53,139; cpp: 12,646; perl: 5,658; sh: 5,369; makefile: 3,435; python: 1,205; yacc: 447; lex: 151; pascal: 58
file content (47 lines) | stat: -rw-r--r-- 986 bytes parent folder | download | duplicates (5)
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
CREATE FUNCTION _timecheck(label text, tolerated interval) RETURNS text
AS $$
DECLARE
  ret TEXT;
  lap INTERVAL;
	rec RECORD;
BEGIN
	-- We use now() here to get the time at the
	-- start of the transaction, which started when
	-- this function was called, so the earliest
	-- possible time
  SELECT now()-t lap, sf slow_factor
	FROM _time INTO rec;

	RAISE DEBUG 'Requested tolerance: %', tolerated;
	RAISE DEBUG 'Slow factor: %', rec.slow_factor;

	tolerated := tolerated * rec.slow_factor;

	RAISE DEBUG 'Resulting tolerance: %', tolerated;

  IF rec.lap <= tolerated THEN
		ret := format(
			'%s interrupted on time',
			label
		);
  ELSE
		ret := format(
			'%s interrupted late: %s (%s tolerated)',
			label, rec.lap, tolerated
		);
  END IF;

  UPDATE _time SET t = clock_timestamp();

  RETURN ret;
END;
$$ LANGUAGE 'plpgsql' VOLATILE;

CREATE TEMPORARY TABLE _time AS
SELECT
	now() t,
	COALESCE(
    current_setting('test.executor_slow_factor', true),
    '1'
  )::float8 sf;