From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id A1C671381F3 for ; Sat, 22 Dec 2012 03:00:12 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 5390521C004; Sat, 22 Dec 2012 03:00:03 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id B687821C004 for ; Sat, 22 Dec 2012 03:00:02 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 5AFCA33C1EF for ; Sat, 22 Dec 2012 03:00:01 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id E04D1E543C for ; Sat, 22 Dec 2012 02:59:59 +0000 (UTC) From: "Magnus Granberg" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Magnus Granberg" Message-ID: <1356145156.2cbdb964e162582123ad5e4d0fe33c178df9d2a2.zorry@gentoo> Subject: [gentoo-commits] dev/zorry:master commit in: gobs/bin/, gobs/pym/ X-VCS-Repository: dev/zorry X-VCS-Files: gobs/bin/gobs_cron gobs/pym/cron.py gobs/pym/mysql_querys.py X-VCS-Directories: gobs/bin/ gobs/pym/ X-VCS-Committer: zorry X-VCS-Committer-Name: Magnus Granberg X-VCS-Revision: 2cbdb964e162582123ad5e4d0fe33c178df9d2a2 X-VCS-Branch: master Date: Sat, 22 Dec 2012 02:59:59 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: c20470cb-6e24-4245-ad66-90577e14beed X-Archives-Hash: c9b5d00ca198817e4d99b4468f133f71 commit: 2cbdb964e162582123ad5e4d0fe33c178df9d2a2 Author: Magnus Granberg gentoo org> AuthorDate: Sat Dec 22 02:59:16 2012 +0000 Commit: Magnus Granberg gentoo org> CommitDate: Sat Dec 22 02:59:16 2012 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=dev/zorry.git;a=commit;h=2cbdb964 add gobs cron --- gobs/bin/gobs_cron | 25 +++++++++++++++++++++++++ gobs/pym/cron.py | 13 +++++++++++++ gobs/pym/mysql_querys.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 0 deletions(-) diff --git a/gobs/bin/gobs_cron b/gobs/bin/gobs_cron new file mode 100644 index 0000000..773700b --- /dev/null +++ b/gobs/bin/gobs_cron @@ -0,0 +1,25 @@ +#!/usr/bin/python +# Distributed under the terms of the GNU General Public License v2 + +from __future__ import print_function + +from gobs.readconf import get_conf_settings +from gobs.cron import cron_main +from gobs.ConnectionManager import connectionManager +from gobs.mysql_querys import add_gobs_logs, get_config_id + +def main(): + # Main + reader = get_conf_settings() + gobs_settings_dict=reader.read_gobs_settings_all() + config_profile = gobs_settings_dict['gobs_config'] + CM=connectionManager() + conn = CM.newConnection() + config_id = get_config_id(conn, config_profile) + add_gobs_logs(conn, "Cron job started", "info", config_id) + cron_main(conn, config_id) + add_gobs_logs(conn, "Cron job done.", "info", config_id) + conn.close + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/gobs/pym/cron.py b/gobs/pym/cron.py new file mode 100644 index 0000000..706719f --- /dev/null +++ b/gobs/pym/cron.py @@ -0,0 +1,13 @@ +from __future__ import print_function + +from gobs.mysql_querys import get_cron_jobs, get_cron_info, check_jobs, \ + add_new_job, add_gobs_logs + +def cron_main(conn, config_id): + cron_id_list = get_cron_jobs(conn, config_id) + for cron_id in cron_id_list: + job_type_id, run_config_id = get_cron_info(conn, cron_id) + if not check_jobs(conn, job_type_id, config_id, run_config_id): + log_msg = "Job: %s added to job list on %s for %s" % (job_type_id, config_id, run_config_id,) + add_gobs_logs(conn, log_msg, "info", config_id) + add_new_job(conn, cron_id, job_type_id, config_id, run_config_id) diff --git a/gobs/pym/mysql_querys.py b/gobs/pym/mysql_querys.py index d9bbcc3..8c531cb 100644 --- a/gobs/pym/mysql_querys.py +++ b/gobs/pym/mysql_querys.py @@ -48,6 +48,48 @@ def update_job_list(connection, status, job_id): connection.commit() cursor.close() +def get_cron_jobs(connection, config_id): + cursor = connection.cursor() + sqlQ = 'SELECT cron_id FROM cron WHERE config_id = %s' + cursor.execute(sqlQ, (config_id,)) + entries = cursor.fetchall() + cursor.close() + if entries is None: + return None + cron_id_list = [] + for cron_id in entries: + cron_id_list.append(cron_id[0]) + return sorted(cron_id_list) + +def check_jobs(connection, job_type_id, config_id, run_config_id): + cursor = connection.cursor() + sqlQ = "SELECT job_id FROM jobs WHERE job_type_id = %s AND config_id = %s AND run_config_id = %s AND (status = 'Runing' OR status = 'Waiting')" + cursor.execute(sqlQ) + entries = cursor.fetchone() + cursor.close() + if entries is None: + return False + return True + +def get_cron_info(connection, cron_id): + cursor = connection.cursor() + sqlQ = 'SELECT job_type_id, run_config_id FROM cron WHERE cron_id = %s' + cursor.execute(sqlQ) + entries = cursor.fetchone() + cursor.close() + job_type_id = entries[0] + run_config_id = entries[1] + return job_type_id, run_config_id + +def add_new_job(connection, cron_id, job_type_id, config_id, run_config_id): + cursor = connection.cursor() + sqlQ1 = "INSERT INTO jobs (job_type_id, user, config_id, run_config_id) VALUES ( %s, 'cron', %s, %s)" + sqlQ2 = 'UPDATE cron SET time_stamp = NOW() WHERE cron_id = %s' + cursor.execute(sqlQ1, (job_type_id, config_id, run_config_id,)) + cursor.execute(sqlQ2(cron_id,)) + connection.commit() + cursor.close() + # Queryes to handel the configs* tables def get_config_list_all(connection): cursor = connection.cursor()