Last active
November 18, 2020 19:11
-
-
Save tashrifbillah/5f2d28ca17f1099aef08d81727d74942 to your computer and use it in GitHub Desktop.
Get record_id of a task stored in SQL database file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sqlite3 | |
from luigi import configuration | |
config = configuration.get_config() | |
def get_record_id(task_id): | |
''' | |
every task has an associated `self.task_id` | |
call `get_record_id(self.task_id)` to obtain that | |
''' | |
conn= sqlite3.connect(config['task_history']['db_connection'].split('sqlite:///')[1]) | |
cur = conn.cursor() | |
cur.execute(f"SELECT id FROM tasks WHERE task_id='{task_id}'") | |
record_id = cur.fetchone()[0] | |
conn.close() | |
return record_id |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If needed, you can use my
luigi.cfg
(place it in the same directory).