Skip to content

Commit

Permalink
add followup_task to PublicItemUsageReporter
Browse files Browse the repository at this point in the history
  • Loading branch information
aaxelb committed Oct 17, 2024
1 parent 19cf2fb commit dee0d94
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions osf/metrics/reporters/public_item_usage.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from __future__ import annotations
import typing

import celery
if typing.TYPE_CHECKING:
import elasticsearch_dsl as edsl

from osf.metadata.osf_gathering import OsfmapPartition
from osf.metrics.counted_usage import (
CountedAuthUsage,
get_item_type,
Expand Down Expand Up @@ -46,6 +48,12 @@ def report(self):
except _SkipItem:
pass

def followup_task(self):
return task__update_monthly_metadatas.signature(
args=[str(self.yearmonth)],
countdown=30, # give index time to settle
)

def _report_from_buckets(self, exact_bucket, contained_views_bucket):
# either exact_bucket or contained_views_bucket may be None, but not both
assert (exact_bucket is not None) or (contained_views_bucket is not None)
Expand Down Expand Up @@ -192,6 +200,24 @@ def _get_view_session_count(self, osfid: str):
return _response.aggregations.agg_session_count.value


###
# followup celery task
@celery.shared_task
def task__update_monthly_metadatas(yearmonth: str):
from api.share.utils import task__update_share
_report_search = (
PublicItemUsageReport.search()
.filter('term', report_yearmonth=yearmonth)
.source(['item_osfid']) # return only the 'item_osfid' field
)
for _hit in _report_search.scan():
task__update_share.delay(
_hit.item_osfid,
is_backfill=True,
osfmap_partition_name=OsfmapPartition.MONTHLY_SUPPLEMENT.name,
)


###
# local helpers

Expand Down

0 comments on commit dee0d94

Please sign in to comment.