|
1 | 1 | import logging |
| 2 | +from framework import sentry |
2 | 3 | from framework.celery_tasks import app as celery_app |
3 | 4 | from django.core.management import call_command |
| 5 | +from django.utils import timezone |
4 | 6 | from osf.models import Registration |
| 7 | +from scripts.approve_registrations import approve_past_pendings |
5 | 8 |
|
6 | 9 | logger = logging.getLogger(__name__) |
7 | 10 |
|
8 | 11 |
|
9 | 12 | @celery_app.task(name='scripts.check_manual_restart_approval') |
10 | 13 | def check_manual_restart_approval(registration_id): |
11 | 14 | try: |
12 | | - try: |
13 | | - registration = Registration.objects.get(_id=registration_id) |
14 | | - except Registration.DoesNotExist: |
| 15 | + registration = Registration.load(registration_id) |
| 16 | + if not registration: |
15 | 17 | logger.error(f"Registration {registration_id} not found") |
16 | 18 | return f"Registration {registration_id} not found" |
17 | 19 |
|
18 | 20 | if registration.is_public or registration.is_registration_approved: |
19 | 21 | return f"Registration {registration_id} already approved/public" |
20 | 22 |
|
| 23 | + approval = registration.registration_approval |
| 24 | + if not approval: |
| 25 | + logger.error(f"Registration {registration_id} has no registration approval object") |
| 26 | + return f"Registration {registration_id} has no registration approval object" |
| 27 | + |
| 28 | + if approval.is_rejected: |
| 29 | + logger.info(f"Registration {registration_id} approval was rejected") |
| 30 | + return f"Registration {registration_id} approval was rejected" |
| 31 | + |
21 | 32 | if registration.archiving: |
22 | | - logger.info(f"Registration {registration_id} still archiving, retrying in 10 minutes") |
| 33 | + logger.debug(f"Registration {registration_id} still archiving, retrying in 10 minutes") |
23 | 34 | check_manual_restart_approval.apply_async( |
24 | 35 | args=[registration_id], |
25 | 36 | countdown=600 |
26 | 37 | ) |
27 | 38 | return f"Registration {registration_id} still archiving, scheduled retry" |
28 | 39 |
|
29 | | - logger.info(f"Processing manual restart approval for registration {registration_id}") |
| 40 | + if timezone.now() < approval.auto_approval_time: |
| 41 | + logger.info(f"Registration {registration_id} not ready for auto-approval yet") |
| 42 | + return f"Registration {registration_id} not ready for auto-approval yet" |
30 | 43 |
|
31 | | - call_command( |
32 | | - 'process_manual_restart_approvals', |
33 | | - registration_id=registration_id, |
34 | | - dry_run=False, |
35 | | - hours_back=24, |
36 | | - verbosity=1 |
37 | | - ) |
| 44 | + logger.debug(f"Processing manual restart approval for registration {registration_id}") |
| 45 | + approve_past_pendings([approval], dry_run=False) |
38 | 46 |
|
39 | 47 | return f"Processed manual restart approval check for registration {registration_id}" |
40 | 48 |
|
41 | 49 | except Exception as e: |
42 | | - logger.error(f"Error processing manual restart approval for {registration_id}: {e}") |
| 50 | + msg = f"Error processing manual restart approval for {registration_id}: {str(e)}" |
| 51 | + logger.error(msg) |
| 52 | + sentry.log_message(msg) |
| 53 | + sentry.log_exception(e) |
43 | 54 | raise |
44 | 55 |
|
45 | 56 |
|
|
0 commit comments