Adds task to apply pins to account table.
This commit is contained in:
parent
621780e9b6
commit
027b0457bf
@ -8,6 +8,8 @@ import json
|
|||||||
|
|
||||||
# external imports
|
# external imports
|
||||||
import celery
|
import celery
|
||||||
|
import psycopg2
|
||||||
|
from psycopg2 import extras
|
||||||
from hexathon import (
|
from hexathon import (
|
||||||
strip_0x,
|
strip_0x,
|
||||||
add_0x,
|
add_0x,
|
||||||
@ -216,3 +218,27 @@ def send_txs(self, nonce):
|
|||||||
|
|
||||||
|
|
||||||
return nonce
|
return nonce
|
||||||
|
|
||||||
|
|
||||||
|
@celery_app.task
|
||||||
|
def set_pins(config: dict, phone_to_pins: list):
|
||||||
|
# define db connection
|
||||||
|
db_conn = psycopg2.connect(
|
||||||
|
database=config.get('database'),
|
||||||
|
host=config.get('host'),
|
||||||
|
port=config.get('port'),
|
||||||
|
user=config.get('user'),
|
||||||
|
password=config.get('password')
|
||||||
|
)
|
||||||
|
db_cursor = db_conn.cursor()
|
||||||
|
|
||||||
|
# batch updates
|
||||||
|
extras.execute_values(db_cursor,
|
||||||
|
'UPDATE account \
|
||||||
|
SET password_hash = update_data.password_hash \
|
||||||
|
FROM (VALUES %s) AS update_data (phone, password_hash) \
|
||||||
|
WHERE phone_number = update_data.phone', phone_to_pins)
|
||||||
|
db_conn.commit()
|
||||||
|
|
||||||
|
db_cursor.close()
|
||||||
|
db_conn.close()
|
||||||
|
Loading…
Reference in New Issue
Block a user