Skip to content

Instantly share code, notes, and snippets.

@tashrifbillah
Last active November 18, 2020 19:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tashrifbillah/5f2d28ca17f1099aef08d81727d74942 to your computer and use it in GitHub Desktop.
Save tashrifbillah/5f2d28ca17f1099aef08d81727d74942 to your computer and use it in GitHub Desktop.
Get record_id of a task stored in SQL database file
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
@tashrifbillah
Copy link
Author

If needed, you can use my luigi.cfg (place it in the same directory).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment