Skip to content

Commit 6d03da9

Browse files
authored
Merge pull request #1623 from AlexsLemonade/avrohom/1588-add-pause-processing-command
Add pause_processing Management Command
2 parents 13afbf7 + c407ab4 commit 6d03da9

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import logging
2+
3+
from django.core.management.base import BaseCommand
4+
from django.template.defaultfilters import pluralize
5+
6+
from scpca_portal.models import Job
7+
8+
logger = logging.getLogger()
9+
logger.setLevel(logging.INFO)
10+
logger.addHandler(logging.StreamHandler())
11+
12+
13+
class Command(BaseCommand):
14+
help = """Pauses all processing jobs and adds them to the pending queue."""
15+
16+
def handle(self, *args, **kwargs):
17+
self.pause_processing()
18+
19+
def pause_processing(self):
20+
termination_reason = "Processing paused via pause_processing command."
21+
terminated_jobs = Job.terminate_processing(reason=termination_reason)
22+
23+
retry_jobs = Job.create_retry_jobs(terminated_jobs)
24+
25+
retry_job_count = len(retry_jobs)
26+
logger.info(
27+
f"{retry_job_count} processing job{pluralize(retry_job_count)} were paused "
28+
"and added to the pending queue."
29+
)

0 commit comments

Comments
 (0)