-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(besoins): Sondage aux prestataires intéressés : cron & task (#1085)
* Setup cron & command * Add Tender task send_tenders_siaes_survey * Additional fixes (filter on tender without transaction info)
- Loading branch information
Showing
6 changed files
with
141 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
clevercloud/tenders_send_siae_transactioned_question_emails.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
lemarche/tenders/management/commands/send_siae_transactioned_question_emails.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from datetime import datetime, timedelta | ||
|
||
from django.core.management.base import BaseCommand | ||
|
||
from lemarche.tenders.models import Tender | ||
from lemarche.www.tenders.tasks import send_tenders_siaes_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" + no info on "transactioned" | ||
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 & no info on transaction & start_working_date J+7 | ||
tender_qs = Tender.objects.sent().filter(siae_transactioned=None) | ||
tender_qs = tender_qs.filter(start_working_date=seven_days_ago) | ||
|
||
self.stdout.write(f"Found {tender_qs.count()} tenders") | ||
|
||
if not dry_run: | ||
email_kind = "transactioned_question_7d" | ||
for tender in tender_qs: | ||
send_tenders_siaes_survey(tender, kind=email_kind) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters