forked from uno-isqa-8950/uno-cpi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jobs.py
92 lines (72 loc) · 3.26 KB
/
jobs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
from apscheduler.schedulers.blocking import BlockingScheduler
from apscheduler.schedulers.background import BackgroundScheduler
import psycopg2
from UnoCPI import sqlfiles,settings
import os
import Project_GEOJSON,Partner_GEOJSON
sched = BlockingScheduler()
sched1 = BackgroundScheduler()
# Initializing the sql files
sql = sqlfiles
#
# @sched.scheduled_job('cron', day_of_week='mon-sun', hour=7)
@sched.scheduled_job( 'interval',hours=6)
def scheduled_job():
print('This job is ran every day at 7 AM GMT/ 2 AM CDT.')
project = 'python Project_GEOJSON.py'
partner = 'python Partner_GEOJSON.py'
os.system(project)
os.system(partner)
global connection
global cursor
try:
connection = psycopg2.connect(user=settings.DATABASES['default']['USER'],
password=settings.DATABASES['default']['PASSWORD'],
host=settings.DATABASES['default']['HOST'],
port=settings.DATABASES['default']['PORT'],
database=settings.DATABASES['default']['NAME'],
sslmode="require")
if connection:
print("Postgres SQL Database successful connection")
cursor = connection.cursor()
# create a temp table with all projects start and end dates
cursor.execute(sql.start_and_end_dates_temp_table_sql)
# fetch all community partners to be set to inactive
# cursor.execute(sql.comm_partners_to_be_set_to_inactive)
#
# inactive_comm_partners = cursor.fetchall()
# print("Here is the list of all projects to be set to inactive", "\n")
# loop to print all the data
# for i in inactive_comm_partners:
# print(i)
# fetch all community partners to be set to active
# cursor.execute(sql.comm_partners_to_be_set_to_active)
#
# active_comm_partners = cursor.fetchall()
# print("Here is the list of all projects to be set to active", "\n")
# loop to print all the data
# for i in active_comm_partners:
# print(i)
# UPDATE PROJECT STATUS TO ACTIVE
cursor.execute(sql.update_project_to_active_sql)
# UPDATE PROJECT STATUS TO COMPLETED
cursor.execute(sql.update_project_to_inactive_sql)
# UPDATE PROJECT STATUS TO COMPLETED
cursor.execute(sql.update_project_to_pending_sql)
# UPDATE COMMUNITY PARTNER WHEN TIED TO A INACTIVE PROJECTS ONLY TO FALSE(INACTIVE)
cursor.execute(sql.update_comm_partner_to_inactive_sql)
# UPDATE COMMUNITY PARTNER WHEN TIED TO A BOTH ACTIVE
# and / or INACTIVE or JUST ACTIVE PROJECTS ONLY TO TRUE(ACTIVE)
cursor.execute(sql.update_comm_partner_to_active_sql)
# drop all_projects_start_and_end_date temp table
cursor.execute(sql.drop_temp_table_all_projects_start_and_end_dates_sql)
except (Exception, psycopg2.Error) as error:
print("Error while connecting to Postgres SQL", error)
finally:
# closing database connection.
if connection:
connection.commit()
cursor.close()
connection.close()
print("Postgres SQL connection is closed")
sched.start()