Skip to content

Commit 482c1c1

Browse files
authored
Merge pull request #278 from mapswipe/fix_logging
Fix logging
2 parents 5e57c33 + 49f5d99 commit 482c1c1

File tree

1 file changed

+41
-13
lines changed

1 file changed

+41
-13
lines changed

mapswipe_workers/mapswipe_workers/mapswipe_workers.py

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ def type_cast_value(self, ctx, value):
3737

3838

3939
@click.group()
40-
@click.option("--verbose", "-v", is_flag=True, help="Enable logging.")
4140
@click.version_option()
41+
@click.option("--verbose", "-v", is_flag=True, help="Enable logging.")
4242
def cli(verbose):
4343
"""Enable logging."""
4444
if not verbose:
@@ -47,6 +47,16 @@ def cli(verbose):
4747

4848
@cli.command("create-projects")
4949
def run_create_projects():
50+
"""
51+
This is the wrapper function to create projects from submitted projects drafts.
52+
We do it this way, to be able to use --verbose flag
53+
for the _run_create_projects function.
54+
Otherwise we can't use --verbose during run function.
55+
"""
56+
_run_create_projects()
57+
58+
59+
def _run_create_projects():
5060
"""
5161
Create projects from submitted project drafts.
5262
@@ -66,6 +76,7 @@ def run_create_projects():
6676
project_drafts = ref.get()
6777

6878
if project_drafts is None:
79+
logger.info("There are no project drafts in firebase.")
6980
return None
7081

7182
for project_draft_id, project_draft in project_drafts.items():
@@ -93,6 +104,17 @@ def run_create_projects():
93104

94105
@cli.command("firebase-to-postgres")
95106
def run_firebase_to_postgres() -> list:
107+
"""
108+
This is the wrapper function to update users and
109+
transfer results from Firebase to Postgres.
110+
We do it this way, to be able to use --verbose flag
111+
for the _run_firebase_to_postgres function.
112+
Otherwise we can't use --verbose during run function.
113+
"""
114+
return _run_firebase_to_postgres()
115+
116+
117+
def _run_firebase_to_postgres() -> list:
96118
"""Update users and transfer results from Firebase to Postgres."""
97119
update_data.update_user_data()
98120
update_data.update_project_data()
@@ -107,10 +129,20 @@ def run_firebase_to_postgres() -> list:
107129
default="[]",
108130
help=(
109131
"Project ids for which to generate stats as a list of strings: "
110-
+ """["project_a", "project_b"]"""
132+
""" '["project_a", "project_b"]' """
111133
),
112134
)
113135
def run_generate_stats(project_ids: list) -> None:
136+
"""
137+
This is the wrapper function to generate statistics for given project ids.
138+
We do it this way, to be able to use --verbose flag
139+
for the _run_generate_stats function.
140+
Otherwise we can't use --verbose during run function.
141+
"""
142+
_run_generate_stats(project_ids)
143+
144+
145+
def _run_generate_stats(project_ids: list) -> None:
114146
"""Generate statistics for given project ids."""
115147
generate_stats.generate_stats(project_ids)
116148

@@ -148,10 +180,7 @@ def run_user_management(email, manager) -> None:
148180

149181
@cli.command("create-tutorial")
150182
@click.option(
151-
"--input-file",
152-
help=(f"A JSON file of the tutorial."),
153-
required=True,
154-
type=str,
183+
"--input-file", help=(f"A JSON file of the tutorial."), required=True, type=str,
155184
)
156185
def run_create_tutorial(input_file) -> None:
157186
"""Create a tutorial project from provided JSON file."""
@@ -196,10 +225,8 @@ def run_archive_project(project_id, project_ids):
196225

197226

198227
@cli.command("run")
199-
@click.option(
200-
"--schedule", is_flag=True, help=("Schedule jobs to run every 10 minutes.")
201-
)
202-
def run(schedule: bool) -> None:
228+
@click.option("--schedule", is_flag=True, help="Schedule jobs to run every 10 minutes.")
229+
def run(schedule):
203230
"""
204231
Run all commands.
205232
@@ -208,9 +235,10 @@ def run(schedule: bool) -> None:
208235
"""
209236

210237
def _run():
211-
run_create_projects()
212-
project_ids = run_firebase_to_postgres()
213-
run_generate_stats(project_ids)
238+
logger.info("start mapswipe backend workflow.")
239+
_run_create_projects()
240+
project_ids = _run_firebase_to_postgres()
241+
_run_generate_stats(project_ids)
214242

215243
if schedule:
216244
sched.every(10).minutes.do(_run)

0 commit comments

Comments
 (0)