Skip to content
This repository has been archived by the owner on Nov 22, 2023. It is now read-only.

Commit

Permalink
(PC-10863) Make context available for log in order to be able to comm…
Browse files Browse the repository at this point in the history
…it and rollback
  • Loading branch information
cgaunet committed Sep 30, 2021
1 parent df90772 commit 637ccb7
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/pcapi/scheduled_tasks/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ def synchronize_titelive_stocks(app):

Exemple :
```python
@log_cron_with_transaction
@cron_context
@log_cron_with_transaction
@cron_require_feature(FeatureToggle.SYNCHRONIZE_TITELIVE)
def synchronize_titelive_stocks(app):
titelive_stocks_provider_id = get_provider_by_local_class(TITELIVE_STOCKS_PROVIDER_NAME).id
Expand Down
12 changes: 6 additions & 6 deletions src/pcapi/scheduled_tasks/algolia_clock.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,38 @@

# FIXME (dbaty, 2021-06-16): rename the file and the cron (and the
# name of the pod).
@log_cron_with_transaction
@cron_context
@log_cron_with_transaction
def index_offers_in_algolia_by_offer(app):
search.index_offers_in_queue()


@log_cron_with_transaction
@cron_context
@log_cron_with_transaction
def index_offers_in_algolia_by_venue(app):
search.index_offers_of_venues_in_queue()


@log_cron_with_transaction
@cron_context
@log_cron_with_transaction
def delete_expired_offers_in_algolia(app):
offers_api.unindex_expired_offers()


@log_cron_with_transaction
@cron_context
@log_cron_with_transaction
def index_offers_in_error_in_algolia_by_offer(app):
search.index_offers_in_queue(from_error_queue=True)


@log_cron_with_transaction
@cron_context
@log_cron_with_transaction
def index_venues(app):
search.index_venues_in_queue()


@log_cron_with_transaction
@cron_context
@log_cron_with_transaction
def index_venues_in_error(app):
search.index_venues_in_queue(from_error_queue=True)

Expand Down
30 changes: 15 additions & 15 deletions src/pcapi/scheduled_tasks/clock.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,31 +39,31 @@
logger = logging.getLogger(__name__)


@log_cron_with_transaction
@cron_context
@log_cron_with_transaction
@cron_require_feature(FeatureToggle.UPDATE_BOOKING_USED)
def update_booking_used(app: Flask) -> None:
bookings_api.auto_mark_as_used_after_event()


@log_cron_with_transaction
@cron_context
@log_cron_with_transaction
@cron_require_feature(FeatureToggle.SYNCHRONIZE_ALLOCINE)
def synchronize_allocine_stocks(app: Flask) -> None:
allocine_stocks_provider_id = get_provider_by_local_class("AllocineStocks").id
synchronize_venue_providers_for_provider(allocine_stocks_provider_id)


@log_cron_with_transaction
@cron_context
@log_cron_with_transaction
def synchronize_provider_api(app: Flask) -> None:
provider_api_stocks.synchronize_stocks()


# FIXME (asaunier, 2021-05-25): This clock must be removed once every application from procedure
# defined in DMS_NEW_ENROLLMENT_PROCEDURE_ID has been treated
@log_cron_with_transaction
@cron_context
@log_cron_with_transaction
def pc_remote_import_beneficiaries(app: Flask) -> None:
procedure_id = settings.DMS_NEW_ENROLLMENT_PROCEDURE_ID
import_from_date = find_most_recent_beneficiary_creation_date_for_source(
Expand All @@ -75,8 +75,8 @@ def pc_remote_import_beneficiaries(app: Flask) -> None:

# FIXME (xordoquy, 2021-06-16): This clock must be removed once every application from procedure
# defined in 44623 has been treated
@log_cron_with_transaction
@cron_context
@log_cron_with_transaction
def pc_remote_import_beneficiaries_from_old_dms(app: Flask) -> None:
if not settings.IS_PROD:
return
Expand All @@ -88,8 +88,8 @@ def pc_remote_import_beneficiaries_from_old_dms(app: Flask) -> None:
remote_tag_has_completed.run(import_from_date, procedure_id)


@log_cron_with_transaction
@cron_context
@log_cron_with_transaction
def pc_import_beneficiaries_from_dms_v3(app: Flask) -> None:
procedure_id = settings.DMS_ENROLLMENT_PROCEDURE_ID_AFTER_GENERAL_OPENING
import_from_date = find_most_recent_beneficiary_creation_date_for_source(
Expand All @@ -99,8 +99,8 @@ def pc_import_beneficiaries_from_dms_v3(app: Flask) -> None:
remote_tag_has_completed.run(import_from_date, procedure_id)


@log_cron_with_transaction
@cron_context
@log_cron_with_transaction
def pc_import_beneficiaries_from_dms_v4(app: Flask) -> None:
for procedure_name, procedure_id in (
("v4_FR", settings.DMS_ENROLLMENT_PROCEDURE_ID_v4_FR),
Expand All @@ -116,20 +116,20 @@ def pc_import_beneficiaries_from_dms_v4(app: Flask) -> None:
remote_tag_has_completed.run(import_from_date, procedure_id)


@log_cron_with_transaction
@cron_context
@log_cron_with_transaction
def pc_handle_expired_bookings(app: Flask) -> None:
handle_expired_bookings()


@log_cron_with_transaction
@cron_context
@log_cron_with_transaction
def pc_notify_soon_to_be_expired_individual_bookings(app: Flask) -> None:
notify_soon_to_be_expired_individual_bookings()


@log_cron_with_transaction
@cron_context
@log_cron_with_transaction
def pc_notify_newly_eligible_users(app: Flask) -> None:
if not settings.IS_PROD and not settings.IS_TESTING:
return
Expand All @@ -138,37 +138,37 @@ def pc_notify_newly_eligible_users(app: Flask) -> None:
send_newly_eligible_user_email(user)


@log_cron_with_transaction
@cron_context
@log_cron_with_transaction
def pc_clean_expired_tokens(app: Flask) -> None:
users_api.delete_expired_tokens()
db.session.commit()


@log_cron_with_transaction
@cron_context
@log_cron_with_transaction
def pc_check_stock_quantity_consistency(app: Flask) -> None:
inconsistent_stocks = check_stock_consistency()
if inconsistent_stocks:
logger.error("Found inconsistent stocks: %s", ", ".join([str(stock_id) for stock_id in inconsistent_stocks]))


@log_cron_with_transaction
@cron_context
@log_cron_with_transaction
def pc_send_tomorrow_events_notifications(app: Flask) -> None:
stock_ids = find_tomorrow_event_stock_ids()
for stock_id in stock_ids:
send_tomorrow_stock_notification.delay(stock_id)


@log_cron_with_transaction
@cron_context
@log_cron_with_transaction
def pc_clean_past_draft_offers(app: Flask) -> None:
delete_past_draft_offers()


@log_cron_with_transaction
@cron_context
@log_cron_with_transaction
def pc_send_withdrawal_terms_to_offerers_validated_yesterday(app: Flask) -> None:
yesterday = date.today() - timedelta(days=1)
offerers_validated_yesterday = get_offerers_by_date_validated(yesterday)
Expand Down
6 changes: 3 additions & 3 deletions src/pcapi/scheduled_tasks/titelive_clock.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@
blueprint = Blueprint(__name__, __name__)


@log_cron_with_transaction
@cron_context
@log_cron_with_transaction
@cron_require_feature(FeatureToggle.SYNCHRONIZE_TITELIVE_PRODUCTS)
def synchronize_titelive_things(app):
synchronize_data_for_provider("TiteLiveThings")


@log_cron_with_transaction
@cron_context
@log_cron_with_transaction
@cron_require_feature(FeatureToggle.SYNCHRONIZE_TITELIVE_PRODUCTS_DESCRIPTION)
def synchronize_titelive_thing_descriptions(app):
synchronize_data_for_provider("TiteLiveThingDescriptions")


@log_cron_with_transaction
@cron_context
@log_cron_with_transaction
@cron_require_feature(FeatureToggle.SYNCHRONIZE_TITELIVE_PRODUCTS_THUMBS)
def synchronize_titelive_thing_thumbs(app):
synchronize_data_for_provider("TiteLiveThingThumbs")
Expand Down

0 comments on commit 637ccb7

Please sign in to comment.