Skip to content

Commit

Permalink
Setup cron & command
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Feb 22, 2024
1 parent 5d10bba commit 63799e2
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 1 deletion.
1 change: 1 addition & 0 deletions clevercloud/cron.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"0 7 * * 2 $ROOT/clevercloud/siaes_send_completion_reminder_emails.sh",
"0 8 * * * $ROOT/clevercloud/siaes_send_user_request_reminder_emails.sh",
"30 8 * * * $ROOT/clevercloud/tenders_send_author_transactioned_question_emails.sh",
"35 8 * * * $ROOT/clevercloud/tenders_send_siae_transactioned_question_emails.sh",
"0 9 * * * $ROOT/clevercloud/tenders_send_siae_contacted_reminder_emails.sh",
"10 9 * * * $ROOT/clevercloud/tenders_send_siae_interested_reminder_emails.sh",
"*/5 8-15 * * 1-5 $ROOT/clevercloud/tenders_send_validated.sh"
Expand Down
22 changes: 22 additions & 0 deletions clevercloud/tenders_send_siae_transactioned_question_emails.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash -l

# Send email for tender transactioned question to siae (interested)

# Do not run if this env var is not set:
if [[ -z "$CRON_TENDER_SEND_SIAE_TRANSACTIONED_QUESTION_ENABLED" ]]; then
echo "CRON_TENDER_SEND_SIAE_TRANSACTIONED_QUESTION_ENABLED not set. Exiting..."
exit 0
fi

# About clever cloud cronjobs:
# https://www.clever-cloud.com/doc/tools/crons/

if [[ "$INSTANCE_NUMBER" != "0" ]]; then
echo "Instance number is ${INSTANCE_NUMBER}. Stop here."
exit 0
fi

# $APP_HOME is set by default by clever cloud.
cd $APP_HOME

django-admin send_siae_transactioned_question_emails
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def add_arguments(self, parser):
)

def handle(self, kind=None, reminder=False, dry_run=False, **options):
self.stdout.write("Script to send email transactioned_question for tenders...")
self.stdout.write("Script to send email tender transactioned_question to authors...")

tender_qs = Tender.objects.sent().filter(survey_transactioned_answer=None)
if kind:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from datetime import datetime, timedelta

from django.core.management.base import BaseCommand

from lemarche.tenders.models import TenderSiae
from lemarche.www.tenders.tasks import send_tenders_siae_survey


seven_days_ago = datetime.today().date() - timedelta(days=7)


class Command(BaseCommand):
"""
Daily script to send an email to tender siaes
Rules
- Tender must be "sent"
- Siae must be "interested"
- Siae must not have received a survey yet
When?
- J+7 after tender start_working_date
Usage:
python manage.py send_siae_transactioned_question_emails --dry-run
python manage.py send_siae_transactioned_question_emails
"""

def add_arguments(self, parser):
parser.add_argument("--kind", type=str, dest="kind")
parser.add_argument("--dry-run", dest="dry_run", action="store_true", help="Dry run, no sends")

def handle(self, kind=None, reminder=False, dry_run=False, **options):
self.stdout.write("Script to send email tender transactioned_question to interested siaes...")

# tender must be sent & start_working_date J+7
tendersiae_qs = TenderSiae.objects.filter(
tender__first_sent_at__isnull=False, tender__start_working_date=seven_days_ago
)
# siae must be interested
tendersiae_qs = tendersiae_qs.filter(detail_contact_click_date__isnull=False)
# siae must not have received the survey yet
tendersiae_qs = tendersiae_qs.filter(survey_transactioned_answer=None, survey_transactioned_send_date=None)

self.stdout.write(f"Found {tendersiae_qs.count()} tendersiaes")

if not dry_run:
email_kind = "transactioned_question_7d"
for tendersiae in tendersiae_qs:
send_tenders_siae_survey(tendersiae, kind=email_kind)
self.stdout.write(f"Sent {tendersiae.count()} {email_kind}")

0 comments on commit 63799e2

Please sign in to comment.