Skip to content

Commit

Permalink
Merge pull request #398 from UW-GAC/feature/cdsa-records-cron
Browse files Browse the repository at this point in the history
Add a cron job for generating CDSA records
  • Loading branch information
amstilp authored Feb 21, 2024
2 parents fc8192d + b13c4d2 commit 5e927db
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
3 changes: 2 additions & 1 deletion primed/cdsa/management/commands/cdsa_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ class Command(BaseCommand):

def add_arguments(self, parser):
parser.add_argument(
"outdir",
"--outdir",
help="""Output directory where reports should be written. This directory will be created.""",
required=True,
)

def _export_table(self, table, filename):
Expand Down
20 changes: 11 additions & 9 deletions primed/cdsa/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ def tearDown(self):

def test_output(self):
out = StringIO()
call_command("cdsa_records", self.outdir, "--no-color", stdout=out)
call_command("cdsa_records", "--outdir", self.outdir, "--no-color", stdout=out)
self.assertIn("generating reports... done!", out.getvalue())

def test_files_created(self):
out = StringIO()
call_command("cdsa_records", self.outdir, "--no-color", stdout=out)
call_command("cdsa_records", "--outdir", self.outdir, "--no-color", stdout=out)
self.assertTrue(isdir(self.outdir))
self.assertTrue(isfile(os.path.join(self.outdir, "representative_records.tsv")))
self.assertTrue(isfile(os.path.join(self.outdir, "study_records.tsv")))
Expand All @@ -37,7 +37,7 @@ def test_files_created(self):

def test_representative_records_zero(self):
out = StringIO()
call_command("cdsa_records", self.outdir, "--no-color", stdout=out)
call_command("cdsa_records", "--outdir", self.outdir, "--no-color", stdout=out)
with open(os.path.join(self.outdir, "representative_records.tsv")) as f:
lines = f.readlines()
self.assertEqual(len(lines), 1)
Expand All @@ -47,14 +47,14 @@ def test_representative_records_three(self):
factories.DataAffiliateAgreementFactory.create()
factories.NonDataAffiliateAgreementFactory.create()
out = StringIO()
call_command("cdsa_records", self.outdir, "--no-color", stdout=out)
call_command("cdsa_records", "--outdir", self.outdir, "--no-color", stdout=out)
with open(os.path.join(self.outdir, "representative_records.tsv")) as f:
lines = f.readlines()
self.assertEqual(len(lines), 4)

def test_study_records_zero(self):
out = StringIO()
call_command("cdsa_records", self.outdir, "--no-color", stdout=out)
call_command("cdsa_records", "--outdir", self.outdir, "--no-color", stdout=out)
with open(os.path.join(self.outdir, "study_records.tsv")) as f:
lines = f.readlines()
self.assertEqual(len(lines), 1)
Expand All @@ -64,14 +64,14 @@ def test_study_records_one(self):
signed_agreement__is_primary=True
)
out = StringIO()
call_command("cdsa_records", self.outdir, "--no-color", stdout=out)
call_command("cdsa_records", "--outdir", self.outdir, "--no-color", stdout=out)
with open(os.path.join(self.outdir, "study_records.tsv")) as f:
lines = f.readlines()
self.assertEqual(len(lines), 2)

def test_cdsa_workspace_records_zero(self):
out = StringIO()
call_command("cdsa_records", self.outdir, "--no-color", stdout=out)
call_command("cdsa_records", "--outdir", self.outdir, "--no-color", stdout=out)
with open(os.path.join(self.outdir, "workspace_records.tsv")) as f:
lines = f.readlines()
self.assertEqual(len(lines), 1)
Expand All @@ -80,7 +80,7 @@ def test_cdsa_workspace_records_one(self):
agreement = factories.DataAffiliateAgreementFactory.create()
factories.CDSAWorkspaceFactory.create(study=agreement.study)
out = StringIO()
call_command("cdsa_records", self.outdir, "--no-color", stdout=out)
call_command("cdsa_records", "--outdir", self.outdir, "--no-color", stdout=out)
with open(os.path.join(self.outdir, "workspace_records.tsv")) as f:
lines = f.readlines()
self.assertEqual(len(lines), 2)
Expand All @@ -89,5 +89,7 @@ def test_directory_exists(self):
os.mkdir(self.outdir)
out = StringIO()
with self.assertRaises(CommandError) as e:
call_command("cdsa_records", self.outdir, "--no-color", stdout=out)
call_command(
"cdsa_records", "--outdir", self.outdir, "--no-color", stdout=out
)
self.assertIn("already exists", str(e.exception))
12 changes: 9 additions & 3 deletions primed_apps.cron
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# PRIMED_APPS crontab
# PRIMED_APPS crontab - maintained in git primed_apps.cron
# Send errors to primedweb email
MAILTO="[email protected]"

# nightly except sunday at 01:00
0 1 * * MON-SAT . /var/www/django/primed_apps/primed-apps-activate.sh; python manage.py run_anvil_audit --email [email protected] --errors-only >> cron.log 2>&1
0 1 * * MON-SAT . /var/www/django/primed_apps/primed-apps-activate.sh; python manage.py run_anvil_audit --email [email protected] --errors-only >> cron.log

# sunday night at 01:00
0 1 * * SUN . /var/www/django/primed_apps/primed-apps-activate.sh; python manage.py run_anvil_audit --email [email protected] >> cron.log 2>&1
0 1 * * SUN . /var/www/django/primed_apps/primed-apps-activate.sh; python manage.py run_anvil_audit --email [email protected] >> cron.log

# Weekly cdsa_records run Sundays at 03:00 - disabled until permissions issues are resolved
0 3 * * SUN . /var/www/django/primed_apps/primed-apps-activate.sh; python manage.py cdsa_records --outdir /projects/primed/records/cdsa/$(date +'\%Y-\%m-\%d') >> cron.log
5 changes: 3 additions & 2 deletions primed_apps_dev.cron
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# PRIMED_APPS_DEV crontab - disabled by default
MAILTO="[email protected]"
# can be enabled for testing.
# nightly except sunday at 01:00
# 0 1 * * MON-SAT . /var/www/django/primed_apps_dev/primed-apps-dev-activate.sh; python manage.py run_anvil_audit --email [email protected] --errors-only >> cron.log 2>&1
# 0 1 * * MON-SAT . /var/www/django/primed_apps_dev/primed-apps-dev-activate.sh; python manage.py run_anvil_audit --email [email protected] --errors-only >> cron.log

# sunday night at 01:00
# 0 1 * * SUN . /var/www/django/primed_apps_dev/primed-apps-dev-activate.sh; python manage.py run_anvil_audit --email [email protected] >> cron.log 2>&1
# 0 1 * * SUN . /var/www/django/primed_apps_dev/primed-apps-dev-activate.sh; python manage.py run_anvil_audit --email [email protected] >> cron.log

0 comments on commit 5e927db

Please sign in to comment.