1 |
commit: a2502fc4a74dfd0aced82648ed3a7a4593a2a476 |
2 |
Author: Magnus Granberg <zorry <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sun Apr 29 14:42:49 2012 +0000 |
4 |
Commit: Magnus Granberg <zorry <AT> gentoo <DOT> org> |
5 |
CommitDate: Sun Apr 29 14:42:49 2012 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=dev/zorry.git;a=commit;h=a2502fc4 |
7 |
|
8 |
adding updatedb to job host deamon |
9 |
|
10 |
--- |
11 |
gobs/bin/gobs_host_jobs | 28 +++++++++++++++++-------- |
12 |
gobs/bin/{gobs_host_jobs => gobs_host_jobs~} | 28 +++++++++++++++++-------- |
13 |
gobs/pym/pgsql.py | 6 ++-- |
14 |
gobs/{bin/gobs_updatedb => pym/updatedb.py} | 11 ++------- |
15 |
4 files changed, 44 insertions(+), 29 deletions(-) |
16 |
|
17 |
diff --git a/gobs/bin/gobs_host_jobs b/gobs/bin/gobs_host_jobs |
18 |
index e6e5ead..87e856e 100755 |
19 |
--- a/gobs/bin/gobs_host_jobs |
20 |
+++ b/gobs/bin/gobs_host_jobs |
21 |
@@ -6,6 +6,8 @@ from __future__ import print_function |
22 |
|
23 |
from gobs.init_setup_profile import setup_profile_main |
24 |
from gobs.readconf import get_conf_settings |
25 |
+from gobs.updatedb import update_db_main |
26 |
+ |
27 |
reader = get_conf_settings() |
28 |
gobs_settings_dict=reader.read_gobs_settings_all() |
29 |
|
30 |
@@ -15,31 +17,39 @@ CM=connectionManager(gobs_settings_dict) |
31 |
#selectively import the pgsql/mysql querys |
32 |
if CM.getName()=='pgsql': |
33 |
from gobs.pgsql import * |
34 |
-# import logging |
35 |
+import logging |
36 |
|
37 |
def main(): |
38 |
# Main |
39 |
config_profile = gobs_settings_dict['gobs_config'] |
40 |
# Logging |
41 |
- #logging.basicConfig(filename=gobs_settings_dict['gobs_logfile'], \ |
42 |
- # format='%(levelname)s: %(asctime)s %(message)s', level=logging.INFO) |
43 |
- conn = CM.getConnection() |
44 |
- CM.putConnection(conn) |
45 |
+ logging.basicConfig(filename=gobs_settings_dict['gobs_logfile'], \ |
46 |
+ format='%(levelname)s: %(asctime)s %(message)s', level=logging.INFO) |
47 |
repeat = True |
48 |
+ logging.info("Job deamon started.") |
49 |
while repeat: |
50 |
conn = CM.getConnection() |
51 |
job = check_job_list(conn, config_profile) |
52 |
- print("job jobid:" + job) |
53 |
+ |
54 |
if job is None: |
55 |
time.sleep(60) |
56 |
CM.putConnection(conn) |
57 |
continue |
58 |
else: |
59 |
- update_job_list("Runing", job[1]) |
60 |
+ logging.info("Job: %s Type: %s Config: %s", job[1], job[0], config_profile) |
61 |
+ if job[0] == "updatedb": |
62 |
+ update_job_list(conn, "Runing", job[1]) |
63 |
+ logging.info("Job %s is runing. Config: %s", job[0], config_profile) |
64 |
+ result = update_db_main() |
65 |
+ if result is True |
66 |
+ update_job_list(conn, "Done", job[1]) |
67 |
+ logging.info("Job %s is done. Config: %s", job[0], config_profile) |
68 |
+ else: |
69 |
+ update_job_list(conn, "Fail", job[1]) |
70 |
+ logging.info("Job %s did fail. Config: %s", job[0], config_profile) |
71 |
repeat = False |
72 |
CM.putConnection(conn) |
73 |
time.sleep(60) |
74 |
- connectionManager.closeAllConnections() |
75 |
- |
76 |
+ |
77 |
if __name__ == "__main__": |
78 |
main() |
79 |
\ No newline at end of file |
80 |
|
81 |
diff --git a/gobs/bin/gobs_host_jobs b/gobs/bin/gobs_host_jobs~ |
82 |
similarity index 54% |
83 |
copy from gobs/bin/gobs_host_jobs |
84 |
copy to gobs/bin/gobs_host_jobs~ |
85 |
index e6e5ead..87e856e 100755 |
86 |
--- a/gobs/bin/gobs_host_jobs |
87 |
+++ b/gobs/bin/gobs_host_jobs~ |
88 |
@@ -6,6 +6,8 @@ from __future__ import print_function |
89 |
|
90 |
from gobs.init_setup_profile import setup_profile_main |
91 |
from gobs.readconf import get_conf_settings |
92 |
+from gobs.updatedb import update_db_main |
93 |
+ |
94 |
reader = get_conf_settings() |
95 |
gobs_settings_dict=reader.read_gobs_settings_all() |
96 |
|
97 |
@@ -15,31 +17,39 @@ CM=connectionManager(gobs_settings_dict) |
98 |
#selectively import the pgsql/mysql querys |
99 |
if CM.getName()=='pgsql': |
100 |
from gobs.pgsql import * |
101 |
-# import logging |
102 |
+import logging |
103 |
|
104 |
def main(): |
105 |
# Main |
106 |
config_profile = gobs_settings_dict['gobs_config'] |
107 |
# Logging |
108 |
- #logging.basicConfig(filename=gobs_settings_dict['gobs_logfile'], \ |
109 |
- # format='%(levelname)s: %(asctime)s %(message)s', level=logging.INFO) |
110 |
- conn = CM.getConnection() |
111 |
- CM.putConnection(conn) |
112 |
+ logging.basicConfig(filename=gobs_settings_dict['gobs_logfile'], \ |
113 |
+ format='%(levelname)s: %(asctime)s %(message)s', level=logging.INFO) |
114 |
repeat = True |
115 |
+ logging.info("Job deamon started.") |
116 |
while repeat: |
117 |
conn = CM.getConnection() |
118 |
job = check_job_list(conn, config_profile) |
119 |
- print("job jobid:" + job) |
120 |
+ |
121 |
if job is None: |
122 |
time.sleep(60) |
123 |
CM.putConnection(conn) |
124 |
continue |
125 |
else: |
126 |
- update_job_list("Runing", job[1]) |
127 |
+ logging.info("Job: %s Type: %s Config: %s", job[1], job[0], config_profile) |
128 |
+ if job[0] == "updatedb": |
129 |
+ update_job_list(conn, "Runing", job[1]) |
130 |
+ logging.info("Job %s is runing. Config: %s", job[0], config_profile) |
131 |
+ result = update_db_main() |
132 |
+ if result is True |
133 |
+ update_job_list(conn, "Done", job[1]) |
134 |
+ logging.info("Job %s is done. Config: %s", job[0], config_profile) |
135 |
+ else: |
136 |
+ update_job_list(conn, "Fail", job[1]) |
137 |
+ logging.info("Job %s did fail. Config: %s", job[0], config_profile) |
138 |
repeat = False |
139 |
CM.putConnection(conn) |
140 |
time.sleep(60) |
141 |
- connectionManager.closeAllConnections() |
142 |
- |
143 |
+ |
144 |
if __name__ == "__main__": |
145 |
main() |
146 |
\ No newline at end of file |
147 |
|
148 |
diff --git a/gobs/pym/pgsql.py b/gobs/pym/pgsql.py |
149 |
index 5ebe500..64f1b46 100644 |
150 |
--- a/gobs/pym/pgsql.py |
151 |
+++ b/gobs/pym/pgsql.py |
152 |
@@ -639,7 +639,7 @@ def make_conf_error(connection,config_profile): |
153 |
|
154 |
def check_job_list(connection, config_profile): |
155 |
cursor = connection.cursor() |
156 |
- sqlQ1 = 'SELECT idnr FROM configs WHERE id = %s' |
157 |
+ sqlQ1 = 'SELECT id_nr FROM configs WHERE id = %s' |
158 |
sqlQ2 = "SELECT job, jobnr FROM jobs_list WHERE status = 'Waiting' AND config_id = %s" |
159 |
cursor.execute(sqlQ1, (config_profile,)) |
160 |
config_nr = cursor.fetchone() |
161 |
@@ -649,8 +649,8 @@ def check_job_list(connection, config_profile): |
162 |
return None |
163 |
return job |
164 |
|
165 |
-def update_job_list(status, jobid): |
166 |
+def update_job_list(connection, status, jobid): |
167 |
cursor = connection.cursor() |
168 |
- sqlQ = 'UPDATE jobs_list SET ststus = %s WHERE jobid = %s' |
169 |
+ sqlQ = 'UPDATE jobs_list SET status = %s WHERE jobnr = %s' |
170 |
cursor.execute(sqlQ, (status, jobid,)) |
171 |
connection.commit() |
172 |
|
173 |
diff --git a/gobs/bin/gobs_updatedb b/gobs/pym/updatedb.py |
174 |
similarity index 95% |
175 |
rename from gobs/bin/gobs_updatedb |
176 |
rename to gobs/pym/updatedb.py |
177 |
index d7bfbee..738179f 100755 |
178 |
--- a/gobs/bin/gobs_updatedb |
179 |
+++ b/gobs/pym/updatedb.py |
180 |
@@ -1,10 +1,9 @@ |
181 |
-#!/usr/bin/python |
182 |
# Copyright 2006-2011 Gentoo Foundation |
183 |
# Distributed under the terms of the GNU General Public License v2 |
184 |
|
185 |
""" This code will update the sql backend with needed info for |
186 |
the Frontend and the Guest deamon. """ |
187 |
- |
188 |
+from __future__ import print_function |
189 |
import sys |
190 |
import os |
191 |
import multiprocessing |
192 |
@@ -110,11 +109,9 @@ def update_cpv_db(mysettings): |
193 |
pool.join() |
194 |
logging.info("Checking categories, package and ebuilds done") |
195 |
|
196 |
-def main(): |
197 |
+def update_db_main(): |
198 |
# Main |
199 |
# Logging |
200 |
- logging.basicConfig(filename=gobs_settings_dict['gobs_logfile'], \ |
201 |
- format='%(levelname)s: %(asctime)s %(message)s', level=logging.INFO) |
202 |
logging.info("Update db started.") |
203 |
# Sync portage and profile/settings |
204 |
git_pull |
205 |
@@ -127,6 +124,4 @@ def main(): |
206 |
update_cpv_db(mysettings) |
207 |
CM.closeAllConnections() |
208 |
logging.info("Update db ... Done.") |
209 |
- |
210 |
-if __name__ == "__main__": |
211 |
- main() |
212 |
\ No newline at end of file |
213 |
+ return True |
214 |
\ No newline at end of file |