-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenqueue.py
More file actions
39 lines (36 loc) · 1.37 KB
/
enqueue.py
File metadata and controls
39 lines (36 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import os
import argparse
from celery import Celery
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Process CSV files and insert sensor readings into the database."
)
parser.add_argument(
"directory", type=str, help="The target directory containing CSV files"
)
parser.add_argument("--dbhost", type=str, help="Database host")
parser.add_argument("--dbname", type=str, help="Database name")
parser.add_argument("--dbuser", type=str, help="Database user")
parser.add_argument("--dbpass", type=str, help="Database password")
parser.add_argument("--dbport", type=str, help="Database port")
args = parser.parse_args()
app = Celery(
"worker",
broker=os.environ.get("BROKER_URL", ""),
)
for filename in os.listdir(args.directory):
f = os.path.join(args.directory, filename)
if os.path.isfile(f):
app.send_task(
"server.worker.process_csv_file.process_csv_file_task",
kwargs={
"file_path": f,
"db_config": {
"host": args.dbhost,
"port": args.dbport,
"user": args.dbuser,
"password": args.dbpass,
"name": args.dbname,
},
},
)