mirror of
https://github.com/ansible/awx.git
synced 2026-02-01 01:28:09 -03:30
Replacing psycopg2.copy_expert with psycopg3.copy
This commit is contained in:
committed by
John Westcott IV
parent
e47d30974c
commit
a665d96026
@@ -98,37 +98,27 @@ class YieldedRows(StringIO):
|
||||
)
|
||||
self.rowlist.append(row)
|
||||
|
||||
def read(self, x):
|
||||
if self.rows <= 0:
|
||||
self.close()
|
||||
return ''
|
||||
elif self.rows >= 1 and self.rows < 1000:
|
||||
event_rows = self.rowlist[random.randrange(len(self.rowlist))] * self.rows
|
||||
self.rows -= self.rows
|
||||
return event_rows
|
||||
self.rows -= 1000
|
||||
return self.rowlist[random.randrange(len(self.rowlist))] * 1000
|
||||
|
||||
|
||||
def firehose(job, count, created_stamp, modified_stamp):
|
||||
conn = psycopg.connect(dsn)
|
||||
f = YieldedRows(job, count, created_stamp, modified_stamp)
|
||||
with conn.cursor() as cursor:
|
||||
cursor.copy_expert(
|
||||
(
|
||||
'COPY '
|
||||
'main_jobevent('
|
||||
'created, modified, job_created, event, event_data, failed, changed, '
|
||||
'host_name, play, role, task, counter, host_id, job_id, uuid, '
|
||||
'parent_uuid, end_line, playbook, start_line, stdout, verbosity'
|
||||
') '
|
||||
'FROM STDIN'
|
||||
),
|
||||
f,
|
||||
size=1024 * 1000,
|
||||
)
|
||||
conn.commit()
|
||||
conn.close()
|
||||
sql = '''
|
||||
COPY main_jobevent(
|
||||
created, modified, job_created, event, event_data, failed, changed,
|
||||
host_name, play, role, task, counter, host_id, job_id, uuid,
|
||||
parent_uuid, end_line, playbook, start_line, stdout, verbosity
|
||||
) FROM STDIN
|
||||
'''
|
||||
try:
|
||||
with conn.cursor() as cursor:
|
||||
with cursor.copy(sql) as copy:
|
||||
copy.write("".join(f.rowlist))
|
||||
except Exception as e:
|
||||
print("Failed to import events")
|
||||
print(e)
|
||||
finally:
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
|
||||
def cleanup(sql):
|
||||
|
||||
Reference in New Issue
Block a user