BO 1.34+3 cron

This commit is contained in:
Tibor Bossanyi (Freelancer) 2021-12-01 00:58:40 +01:00
parent 5bbb165de5
commit a4a6a5ef36
4 changed files with 24 additions and 14 deletions

View File

@ -21,6 +21,7 @@ DEBUG = False
ALLOWED_HOSTS = ['62.171.188.119', ALLOWED_HOSTS = ['62.171.188.119',
"admin.aitrainer.app", "admin.aitrainer.app",
'mail.aitrainer.info', 'mail.aitrainer.info',
'mail.aitrainer.app'
'aitrainer.info', 'aitrainer.info',
'www.aitrainer.info', 'www.aitrainer.info',
'aitrainer.app', 'aitrainer.app',
@ -181,4 +182,6 @@ LOGGING = {
CRON_CLASSES = [ CRON_CLASSES = [
'controlling.cron.cron.NotificationJob', 'controlling.cron.cron.NotificationJob',
'controlling.cron.cron.TrialJob',
'controlling.cron.cron.LangJob',
] ]

View File

@ -14,11 +14,6 @@ else:
class Mautic: class Mautic:
def syncTrial(self):
tenDays = datetime.datetime - datetime.timedelta(days=10)
qs = Customer.objects.raw(
'SELECT * from customer WHERE trial_date < "' + tenDays + '" and trial_date is not null')
def syncLang(self): def syncLang(self):
qs = Customer.objects.raw('SELECT * from customer WHERE lang is not null and lang_sync is null') qs = Customer.objects.raw('SELECT * from customer WHERE lang is not null and lang_sync is null')
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -33,12 +28,12 @@ class Mautic:
data = "mauticform[email]=" + customer.email + \ data = "mauticform[email]=" + customer.email + \
"&mauticform[database_id]=" + str(customer.customer_id) + \ "&mauticform[database_id]=" + str(customer.customer_id) + \
"&mauticform[lang]=" + str(customer.lang) + \ "&mauticform[lang]=" + str(customer.lang) + \
"&mauticform[formId]=3" + \ "&mauticform[formId]=7" + \
"&mauticform[formName]=appdatachange" "&mauticform[formName]=appdatachange"
print(data) print(data)
form_url = 'https://mautic.aitrainer.app/form/submit?formId=3' form_url = 'https://mautic.aitrainer.app/form/submit?formId=7'
response = requests.post(form_url, data=data.encode('utf-8'), headers=headers) response = requests.post(form_url, data=data.encode('utf-8'), headers=headers)
print(customer.email + " " +str(response.status_code)) print(customer.email + " " +str(response.status_code))
@ -54,7 +49,7 @@ class Mautic:
return True return True
def syncTrial(self): def syncTrial(self):
qs = Customer.objects.raw('SELECT * from customer WHERE trial_date is not null and trial_date_sync is null') qs = Customer.objects.raw('SELECT * from customer WHERE trial_date is not null and trial_date != "1900-01-01 00:00:00 00:00" and trial_date_sync is null')
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
logger.info("Syncronising trial date...") logger.info("Syncronising trial date...")
@ -67,12 +62,12 @@ class Mautic:
data = "mauticform[email]=" + customer.email + \ data = "mauticform[email]=" + customer.email + \
"&mauticform[database_id]=" + str(customer.customer_id) + \ "&mauticform[database_id]=" + str(customer.customer_id) + \
"&mauticform[trialdate]=" + str(customer.trial_date) + \ "&mauticform[trialdate]=" + str(customer.trial_date) + \
"&mauticform[formId]=3" + \ "&mauticform[formId]=7" + \
"&mauticform[formName]=appdatachange" "&mauticform[formName]=appdatachange"
print(data) print(data)
form_url = 'https://mautic.aitrainer.app/form/submit?formId=3' form_url = 'https://mautic.aitrainer.app/form/submit?formId=7'
response = requests.post(form_url, data=data.encode('utf-8'), headers=headers) response = requests.post(form_url, data=data.encode('utf-8'), headers=headers)
print(customer.email + " " +str(response.status_code)) print(customer.email + " " +str(response.status_code))

View File

@ -26,8 +26,7 @@ class NotificationJob(CronJobBase):
print(datetime.datetime.now(), " *** END notification ") print(datetime.datetime.now(), " *** END notification ")
class TrialJob(CronJobBase): class TrialJob(CronJobBase):
RUN_EVERY_MINS = 60 RUN_EVERY_MINS = 60
schedule = Schedule(run_every_mins=RUN_EVERY_MINS) schedule = Schedule(run_every_mins=RUN_EVERY_MINS)
code = 'aitrainer_backoffice.controlling.trial_sync' # a unique code code = 'aitrainer_backoffice.controlling.trial_sync' # a unique code
@ -37,5 +36,17 @@ class TrialJob(CronJobBase):
mautic = Mautic() mautic = Mautic()
mautic.syncTrial() mautic.syncTrial()
print(datetime.datetime.now(), " *** END trial sync ") print(datetime.datetime.now(), " *** END trial sync ")
class LangJob(CronJobBase):
RUN_EVERY_MINS = 60
schedule = Schedule(run_every_mins=RUN_EVERY_MINS)
code = 'aitrainer_backoffice.controlling.Lang_sync' # a unique code
def do(self):
print(datetime.datetime.now(), " *** START Lang sync ")
mautic = Mautic()
mautic.syncLang()
print(datetime.datetime.now(), " *** END Lang sync ")

View File

@ -39,7 +39,8 @@ services:
- GOOGLE_APPLICATION_CREDENTIALS=/aitrainer_backoffice/aitrainer_backoffice/aitrainer_backoffice/asset/aitrainer-firebase-adminsdk.json - GOOGLE_APPLICATION_CREDENTIALS=/aitrainer_backoffice/aitrainer_backoffice/aitrainer_backoffice/asset/aitrainer-firebase-adminsdk.json
- WORKOUTTEST_SETTING=PROD - WORKOUTTEST_SETTING=PROD
command: gunicorn aitrainer_backoffice.aitrainer_backoffice.wsgi --env DJANGO_SETTINGS_MODULE=aitrainer_backoffice.aitrainer_backoffice.settings.prod --bind 0.0.0.0:8000 --workers 3 command: gunicorn aitrainer_backoffice.aitrainer_backoffice.wsgi --env DJANGO_SETTINGS_MODULE=aitrainer_backoffice.aitrainer_backoffice.settings.prod --bind 0.0.0.0:8000 --workers 3
cronjobs:
cronjobs:
build: build:
context: . context: .
dockerfile: ./Dockerfile dockerfile: ./Dockerfile
@ -102,7 +103,7 @@ cronjobs:
consistency: cached consistency: cached
- /usr/local/bin/wordpress/wp-content/uploads:/var/www/html/wp-content/uploads:cached - /usr/local/bin/wordpress/wp-content/uploads:/var/www/html/wp-content/uploads:cached
mautic: mautic:
image: mautic/mautic:v3 image: mautic/mautic:v3
container_name: mautic container_name: mautic
links: links: