-
Notifications
You must be signed in to change notification settings - Fork 358
Expand file tree
/
Copy pathcheck_manual_restart_approval.py
More file actions
83 lines (63 loc) · 3.29 KB
/
check_manual_restart_approval.py
File metadata and controls
83 lines (63 loc) · 3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import logging
from framework import sentry
from framework.celery_tasks import app as celery_app
from django.core.management import call_command
from django.utils import timezone
from osf.models import Registration
from scripts.approve_registrations import approve_past_pendings
logger = logging.getLogger(__name__)
@celery_app.task(name='scripts.check_manual_restart_approval')
def check_manual_restart_approval(registration_id):
try:
registration = Registration.load(registration_id)
if not registration:
logger.error(f"Registration {registration_id} not found")
return f"Registration {registration_id} not found"
if registration.is_public or registration.is_registration_approved:
return f"Registration {registration_id} already approved/public"
approval = registration.registration_approval
if not approval:
logger.info(f"Registration {registration_id} has no registration approval object")
return f"Registration {registration_id} has no registration approval object"
if approval.is_rejected:
logger.info(f"Registration {registration_id} approval was rejected")
return f"Registration {registration_id} approval was rejected"
if registration.archiving:
logger.info(f"Registration {registration_id} still archiving, retrying in 10 minutes")
check_manual_restart_approval.apply_async(
args=[registration_id],
countdown=600
)
return f"Registration {registration_id} still archiving, scheduled retry"
if timezone.now() < approval.auto_approve_at:
logger.info(f"Registration {registration_id} not ready for auto-approval yet")
return f"Registration {registration_id} not ready for auto-approval yet"
logger.info(f"Processing manual restart approval for registration {registration_id}")
approve_past_pendings([approval], dry_run=False)
return f"Processed manual restart approval check for registration {registration_id}"
except Exception as e:
logger.error(f"Error processing manual restart approval for {registration_id}: {e}")
sentry.log_exception(e)
raise
@celery_app.task(name='scripts.check_manual_restart_approvals_batch')
def check_manual_restart_approvals_batch(hours_back=24):
try:
logger.info(f"Running batch check for manual restart approvals (last {hours_back} hours)")
call_command(
'process_manual_restart_approvals',
dry_run=False,
hours_back=hours_back,
verbosity=1
)
return f"Completed batch manual restart approval check for last {hours_back} hours"
except Exception as e:
logger.error(f"Error in batch manual restart approval check: {e}")
raise
@celery_app.task(name='scripts.delayed_manual_restart_approval')
def delayed_manual_restart_approval(registration_id, delay_minutes=30):
logger.info(f"Scheduling delayed manual restart approval check for {registration_id} in {delay_minutes} minutes")
check_manual_restart_approval.apply_async(
args=[registration_id],
countdown=delay_minutes * 60
)
return f"Scheduled manual restart approval check for {registration_id} in {delay_minutes} minutes"