Add renew_ts column and check with renew_ts
This commit is contained in:
parent
ce0ce20e3a
commit
6a033ea948
3 changed files with 17 additions and 4 deletions
7
docs/schema-upgrade-1.32-1.33.sql
Normal file
7
docs/schema-upgrade-1.32-1.33.sql
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
-- upgrade script to migrate the Koji database schema
|
||||
-- from version 1.32 to 1.33
|
||||
|
||||
BEGIN;
|
||||
ALTER TABLE sessions ADD COLUMN renew_time TIMESTAMPTZ DEFAULT NULL;
|
||||
COMMIT;
|
||||
|
||||
|
|
@ -120,6 +120,7 @@ CREATE TABLE sessions (
|
|||
update_time TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
exclusive BOOLEAN CHECK (exclusive),
|
||||
closed BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
renew_time TIMESTAMPTZ DEFAULT NULL,
|
||||
CONSTRAINT no_exclusive_subsessions CHECK (
|
||||
master IS NULL OR "exclusive" IS NULL),
|
||||
CONSTRAINT no_closed_exclusive CHECK (
|
||||
|
|
|
|||
|
|
@ -117,7 +117,8 @@ class Session(object):
|
|||
fields = (('authtype', 'authtype'), ('callnum', 'callnum'), ('exclusive', 'exclusive'),
|
||||
('expired', 'expired'), ('master', 'master'), ('start_time', 'start_time'),
|
||||
('update_time', 'update_time'), ("date_part('epoch', start_time)", 'start_ts'),
|
||||
("date_part('epoch', update_time)", 'update_ts'), ('user_id', 'user_id'))
|
||||
("date_part('epoch', update_time)", 'update_ts'), ('user_id', 'user_id'),
|
||||
("date_part('epoch', renew_time)", 'renew_ts'))
|
||||
columns, aliases = zip(*fields)
|
||||
|
||||
query = QueryProcessor(tables=['sessions'], columns=columns, aliases=aliases,
|
||||
|
|
@ -139,8 +140,12 @@ class Session(object):
|
|||
raise koji.AuthError('Invalid session or bad credentials')
|
||||
|
||||
if not session_data['expired'] and context.opts['SessionRenewalTimeout'] != 0:
|
||||
renewal_cutoff = (session_data['start_ts'] +
|
||||
context.opts['SessionRenewalTimeout'] * 60)
|
||||
if session_data['renew_ts']:
|
||||
renewal_cutoff = (session_data['renew_ts'] +
|
||||
context.opts['SessionRenewalTimeout'] * 60)
|
||||
else:
|
||||
renewal_cutoff = (session_data['start_ts'] +
|
||||
context.opts['SessionRenewalTimeout'] * 60)
|
||||
if time.time() > renewal_cutoff:
|
||||
session_data['expired'] = True
|
||||
update = UpdateProcessor('sessions',
|
||||
|
|
@ -535,7 +540,7 @@ class Session(object):
|
|||
|
||||
update = UpdateProcessor('sessions',
|
||||
clauses=['id=%(id)i'],
|
||||
rawdata={'update_time': 'NOW()'},
|
||||
rawdata={'update_time': 'NOW()', 'renew_time': 'NOW()'},
|
||||
data={'key': self.key, 'expired': False},
|
||||
values={'id': self.id})
|
||||
update.execute()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue