-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add procrastinate to generate parquets
- Loading branch information
Showing
9 changed files
with
849 additions
and
25 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
|
||
set -ex | ||
|
||
export PYTHONPATH=. | ||
pdm run procrastinate --app=tasks.app schema --apply || true | ||
|
||
exec "$@" |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import os | ||
import pathlib | ||
from procrastinate import App, PsycopgConnector | ||
|
||
from parsers.parser import detect_file | ||
|
||
DATABASE_URL = os.getenv("DATABASE_URL") | ||
|
||
DATA_PATH = pathlib.Path(os.getenv("DATA_PATH", '/data/')) | ||
|
||
LOGGERS_PATH = DATA_PATH / 'loggers' | ||
SPREADSHEETS_PATH = DATA_PATH / 'metadata' | ||
PARQUET_PATH = DATA_PATH / 'parquet' | ||
|
||
if not DATABASE_URL: | ||
raise Exception('Missing DATABASE_URL') | ||
|
||
app = App( | ||
connector=PsycopgConnector( | ||
conninfo=DATABASE_URL | ||
) | ||
) | ||
|
||
|
||
@app.task(name='to_parquet') | ||
def to_parquet(file_path: str): | ||
parser = detect_file(path=pathlib.Path(file_path)) | ||
parser.write_parquet(PARQUET_PATH) | ||
|
||
|
||
@app.periodic(cron="* * * * *") | ||
@app.task(name='check_missing') | ||
def check_missing(timestamp: int): | ||
for f in LOGGERS_PATH.iterdir(): | ||
if not (PARQUET_PATH / (f.name + '.parquet')).exists(): | ||
print(f.name + ' not found, adding a task to generate it') | ||
to_parquet.configure(lock=f.name).defer(file_path=str(f)) |
Oops, something went wrong.