BO 1.34+6 no data sync
This commit is contained in:
parent
67ac1e1ddd
commit
c98528d5f0
@ -13,6 +13,8 @@ RUN chmod 0644 /etc/cron.d/aitrainer-cron
|
|||||||
# Apply cron job
|
# Apply cron job
|
||||||
RUN crontab /etc/cron.d/aitrainer-cron
|
RUN crontab /etc/cron.d/aitrainer-cron
|
||||||
|
|
||||||
|
RUN chmod +x /aitrainer_backoffice/cron.sh
|
||||||
|
|
||||||
RUN pip3 install uwsgi
|
RUN pip3 install uwsgi
|
||||||
COPY requirements.txt ./
|
COPY requirements.txt ./
|
||||||
RUN pip install --no-cache-dir -r requirements.txt
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
@ -182,6 +182,6 @@ LOGGING = {
|
|||||||
|
|
||||||
CRON_CLASSES = [
|
CRON_CLASSES = [
|
||||||
'controlling.cron.cron.NotificationJob',
|
'controlling.cron.cron.NotificationJob',
|
||||||
'controlling.cron.cron.TrialJob',
|
|
||||||
'controlling.cron.cron.LangJob',
|
'controlling.cron.cron.LangJob',
|
||||||
|
'controlling.cron.cron.NoDataJob',
|
||||||
]
|
]
|
||||||
|
@ -14,6 +14,75 @@ else:
|
|||||||
|
|
||||||
class Mautic:
|
class Mautic:
|
||||||
|
|
||||||
|
def syncNoDataOldDownloaders(self):
|
||||||
|
qs = Customer.objects.raw('SELECT * FROM customer c left join exercises e on c.customer_id = e.customer_id WHERE trial_date_sync <= NOW() - INTERVAL 2 DAY AND e.exercise_id is null AND c.last_exercise_sync is null')
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
logger.info("Syncronising lang...")
|
||||||
|
|
||||||
|
headers = {
|
||||||
|
'content-type': "application/x-www-form-urlencoded",
|
||||||
|
'cache-control': "no-cache"
|
||||||
|
}
|
||||||
|
index = 0
|
||||||
|
for customer in qs:
|
||||||
|
data = "mauticform[email]=" + customer.email + \
|
||||||
|
"&mauticform[database_id]=" + str(customer.customer_id) + \
|
||||||
|
"&mauticform[lastexercise]=1900-01-01" + \
|
||||||
|
"&mauticform[formId]=7" + \
|
||||||
|
"&mauticform[formName]=appdatasync"
|
||||||
|
|
||||||
|
print(data)
|
||||||
|
|
||||||
|
form_url = 'https://mautic.aitrainer.app/form/submit?formId=7'
|
||||||
|
response = requests.post(form_url, data=data.encode('utf-8'), headers=headers)
|
||||||
|
print(customer.email + " " +str(response.status_code))
|
||||||
|
|
||||||
|
if response.status_code == 200:
|
||||||
|
with connections["live"].cursor() as cursor:
|
||||||
|
cursor.execute("UPDATE customer SET last_exercise_sync = NOW() WHERE customer_id="
|
||||||
|
+ str(customer.customer_id))
|
||||||
|
print(f'customer {customer.customer_id} is updated')
|
||||||
|
|
||||||
|
index = index + 1
|
||||||
|
|
||||||
|
print( "Syncronised customer count: " + str(index))
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def syncNoDataNewSubscribes(self):
|
||||||
|
qs = Customer.objects.raw('SELECT * FROM customer c left join exercises e on c.customer_id = e.customer_id WHERE c.date_add <= NOW() - INTERVAL 2 DAY AND e.exercise_id is null AND c.last_exercise_sync is null')
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
logger.info("Syncronising lang...")
|
||||||
|
|
||||||
|
headers = {
|
||||||
|
'content-type': "application/x-www-form-urlencoded",
|
||||||
|
'cache-control': "no-cache"
|
||||||
|
}
|
||||||
|
index = 0
|
||||||
|
for customer in qs:
|
||||||
|
data = "mauticform[email]=" + customer.email + \
|
||||||
|
"&mauticform[database_id]=" + str(customer.customer_id) + \
|
||||||
|
"&mauticform[lastexercise]=1900-01-01" + \
|
||||||
|
"&mauticform[formId]=7" + \
|
||||||
|
"&mauticform[formName]=appdatasync"
|
||||||
|
|
||||||
|
print(data)
|
||||||
|
|
||||||
|
form_url = 'https://mautic.aitrainer.app/form/submit?formId=7'
|
||||||
|
response = requests.post(form_url, data=data.encode('utf-8'), headers=headers)
|
||||||
|
print(customer.email + " " +str(response.status_code))
|
||||||
|
|
||||||
|
if response.status_code == 200:
|
||||||
|
with connections["live"].cursor() as cursor:
|
||||||
|
cursor.execute("UPDATE customer SET last_exercise_sync = NOW() WHERE customer_id="
|
||||||
|
+ str(customer.customer_id))
|
||||||
|
print(f'customer {customer.customer_id} is updated')
|
||||||
|
|
||||||
|
index = index + 1
|
||||||
|
|
||||||
|
print( "Syncronised customer count: " + str(index))
|
||||||
|
return True
|
||||||
|
|
||||||
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__)
|
||||||
|
@ -39,3 +39,15 @@ class LangJob(CronJobBase):
|
|||||||
print(datetime.datetime.now(), " *** END Lang sync ")
|
print(datetime.datetime.now(), " *** END Lang sync ")
|
||||||
|
|
||||||
|
|
||||||
|
class NoDataJob(CronJobBase):
|
||||||
|
RUN_EVERY_MINS = 60
|
||||||
|
schedule = Schedule(run_every_mins=RUN_EVERY_MINS)
|
||||||
|
code = 'aitrainer_backoffice.controlling.nodata' # a unique code
|
||||||
|
|
||||||
|
def do(self):
|
||||||
|
print(datetime.datetime.now(), " *** START NoData sync ")
|
||||||
|
mautic = Mautic()
|
||||||
|
mautic.syncNoDataNewSubscribes()
|
||||||
|
mautic.syncNoDataOldDownloaders()
|
||||||
|
print(datetime.datetime.now(), " *** END NoData sync ")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user