Skip to content

Commit ab483c2

Browse files
Merge pull request #96 from pitangainnovare/impl/include-params-days-to-go-back
Impl/include params days to go back
2 parents a1f088a + 523e154 commit ab483c2

4 files changed

Lines changed: 17 additions & 8 deletions

File tree

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.9.1
1+
1.10.0

core/utils/date_utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ def get_date_range_str(from_date_str: str = None, until_date_str: str = None, da
3636
"""
3737
Get the date range to be used in the queries.
3838
39+
If both from_date_str and until_date_str are provided, they will be used.
40+
If only one is provided, it will be used as the start or end date, and the other will be calculated based on a 7-day range.
41+
If neither is provided, the function will default to the last 7 days from today.
42+
If days_to_go_back is provided, it will override the from_date_str and until_date_str.
43+
3944
Args:
4045
from_date_str: Date to start the query.
4146
until_date_str: Date to end the query.

log_manager/tasks.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,15 @@ def _fetch_validation_parameters(collection, default_buffer_size=0.1, default_sa
169169

170170

171171
@celery_app.task(bind=True, name=_('Check missing log files'))
172-
def task_check_missing_logs_for_date_range(self, collections=[], from_date=None, until_date=None, user_id=None, username=None):
172+
def task_check_missing_logs_for_date_range(self, collections=[], from_date=None, until_date=None, days_to_go_back=None, user_id=None, username=None):
173173
"""
174174
Task to check for missing log files in the defined date range.
175175
176176
Parameters:
177177
collections (list, optional): List of collection acronyms. Defaults to [].
178178
from_date (str, optional): The start date for log discovery in YYYY-MM-DD format. Defaults to None.
179179
until_date (str, optional): The end date for log discovery in YYYY-MM-DD format. Defaults to None.
180+
days_to_go_back (int, optional): The number of days to go back from today for log discovery. Defaults to None.
180181
user_id (int, optional): The ID of the user initiating the task. Defaults to None.
181182
username (str, optional): The username of the user initiating the task. Defaults to None.
182183
@@ -186,9 +187,11 @@ def task_check_missing_logs_for_date_range(self, collections=[], from_date=None,
186187
"""
187188
user = _get_user(self.request, username=username, user_id=user_id)
188189

190+
from_date_str, until_date_str = date_utils.get_date_range_str(from_date, until_date, days_to_go_back)
191+
189192
for col in collections or Collection.acron3_list():
190193
collection = Collection.objects.get(acron3=col)
191-
for date in date_utils.get_date_objs_from_date_range(from_date, until_date):
194+
for date in date_utils.get_date_objs_from_date_range(from_date_str, until_date_str):
192195
logging.info(f'Checking missings logs for collection {col} and date {date}')
193196
_check_missing_logs_for_date(user, collection, date)
194197

@@ -214,8 +217,8 @@ def _check_missing_logs_for_date(user, collection, date):
214217

215218

216219
@celery_app.task(bind=True, name=_('Generate log files count report'))
217-
def task_log_files_count_status_report(self, collections=[], from_date=None, until_date=None, user_id=None, username=None):
218-
from_date, until_date = date_utils.get_date_range_str(from_date, until_date)
220+
def task_log_files_count_status_report(self, collections=[], from_date=None, until_date=None, days_to_go_back=None, user_id=None, username=None):
221+
from_date, until_date = date_utils.get_date_range_str(from_date, until_date, days_to_go_back)
219222

220223
from_date_obj = date_utils.get_date_obj(from_date)
221224
until_date_obj = date_utils.get_date_obj(until_date)

metrics/tasks.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,22 @@
4848

4949

5050
@celery_app.task(bind=True, name=_('Compute access'), timelimit=-1)
51-
def task_parse_logs(self, collections=[], from_date=None, until_date=None, user_id=None, username=None):
51+
def task_parse_logs(self, collections=[], from_date=None, until_date=None, days_to_go_back=None, user_id=None, username=None):
5252
"""
5353
Parses log files associated with a given collection.
5454
5555
Args:
5656
collections (list, optional): List of collection acronyms to parse logs for. Defaults to all collections.
5757
from_date (str, optional): Start date for log parsing in 'YYYY-MM-DD' format. Defaults to None.
5858
until_date (str, optional): End date for log parsing in 'YYYY-MM-DD' format. Defaults to None.
59+
days_to_go_back (int, optional): Number of days to go back from the current date to parse logs. Defaults to None.
5960
user_id
6061
username
6162
6263
Returns:
6364
None.
6465
"""
65-
from_date, until_date = get_date_range_str(from_date, until_date)
66+
from_date, until_date = get_date_range_str(from_date, until_date, days_to_go_back)
6667

6768
from_date_obj = get_date_obj(from_date)
6869
until_date_obj = get_date_obj(until_date)
@@ -373,7 +374,7 @@ def task_delete_documents_by_key(self, keys, values, index_name=None, user_id=No
373374
logging.error(f"Failed to delete documents with keys {keys} and values {values} from index {index_name}: {e}")
374375

375376

376-
@celery_app.task(bind=True, name=_('Compute metrics'), timelimit=-1)
377+
@celery_app.task(bind=True, name=_('Index metrics'), timelimit=-1)
377378
def task_index_documents(self, collections=[], from_date=None, until_date=None, days_to_go_back=None, user_id=None, username=None, bulk_size=5000, replace=False):
378379
"""
379380
Task to compute and index metrics for specified collections within a given date range.

0 commit comments

Comments
 (0)