Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #122 from Lonnen/697772-reports-clean-cron
Bug 697772 add update_reports_clean cron
- Loading branch information
Showing
4 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import socorro.lib.ConfigurationManager as cm | ||
|
||
try: | ||
from config.commonconfig import * | ||
except ImportError: | ||
from commonconfig import * | ||
|
||
#------------------------------------------------------------------------------- | ||
# Logging | ||
|
||
syslogHost = cm.Option() | ||
syslogHost.doc = 'syslog hostname' | ||
syslogHost.default = 'localhost' | ||
|
||
syslogPort = cm.Option() | ||
syslogPort.doc = 'syslog port' | ||
syslogPort.default = 514 | ||
|
||
syslogFacilityString = cm.Option() | ||
syslogFacilityString.doc = 'syslog facility string ("user", "local0", etc)' | ||
syslogFacilityString.default = 'user' | ||
|
||
syslogLineFormatString = cm.Option() | ||
syslogLineFormatString.doc = 'python logging system format for syslog entries' | ||
syslogLineFormatString.default = 'Socorro Duplicate Detector (pid %(process)d): %(asctime)s %(levelname)s - %(threadName)s - %(message)s' | ||
|
||
syslogErrorLoggingLevel = cm.Option() | ||
syslogErrorLoggingLevel.doc = 'logging level for the log file (10 - DEBUG, 20 - INFO, 30 - WARNING, 40 - ERROR, 50 - CRITICAL)' | ||
syslogErrorLoggingLevel.default = 10 | ||
|
||
stderrLineFormatString = cm.Option() | ||
stderrLineFormatString.doc = 'python logging system format for logging to stderr' | ||
stderrLineFormatString.default = '%(asctime)s %(levelname)s - %(message)s' | ||
|
||
stderrErrorLoggingLevel = cm.Option() | ||
stderrErrorLoggingLevel.doc = 'logging level for the logging to stderr (10 - DEBUG, 20 - INFO, 30 - WARNING, 40 - ERROR, 50 - CRITICAL)' | ||
stderrErrorLoggingLevel.default = 10 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/bash | ||
|
||
. /etc/socorro/socorrorc | ||
|
||
NAME=`basename $0 .sh` | ||
lock $NAME | ||
pyjob $NAME startReportsClean | ||
EXIT_CODE=$? | ||
unlock $NAME | ||
|
||
exit $EXIT_CODE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#! /usr/bin/env python | ||
|
||
import sys | ||
import logging | ||
import logging.handlers | ||
|
||
try: | ||
import config.reportscleanconfig as configModule | ||
except ImportError: | ||
import reportscleanconfig as configModule | ||
|
||
import socorro.lib.ConfigurationManager as configurationManager | ||
import socorro.cron.reportsClean as reportsClean | ||
import socorro.lib.util as sutil | ||
|
||
try: | ||
config = configurationManager.newConfiguration(configurationModule=configModule, applicationName="Reports Clean 0.1") | ||
except configurationManager.NotAnOptionError, x: | ||
print >>sys.stderr, x | ||
print >>sys.stderr, "for usage, try --help" | ||
sys.exit() | ||
|
||
logger = logging.getLogger("reportsClean") | ||
logger.setLevel(logging.DEBUG) | ||
|
||
sutil.setupLoggingHandlers(logger, config) | ||
sutil.echoConfig(logger, config) | ||
|
||
try: | ||
reportsClean.update_reports_clean(config) | ||
finally: | ||
logger.info("done.") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import logging | ||
from datetime import datetime | ||
from datetime import timedelta | ||
|
||
logger = logging.getLogger("reports_clean") | ||
|
||
import socorro.lib.psycopghelper as psy | ||
import socorro.lib.util as util | ||
|
||
#----------------------------------------------------------------------------------------------------------------- | ||
def update_reports_clean(config): | ||
databaseConnectionPool = psy.DatabaseConnectionPool(config.databaseHost, config.databaseName, config.databaseUserName, config.databasePassword, logger) | ||
try: | ||
connection, cursor= databaseConnectionPool.connectionCursorPair() | ||
|
||
startTime = datetime.now() - timedelta(hours=2) | ||
cursor.callproc('update_reports_clean', (startTime)) | ||
connection.commit() | ||
finally: | ||
databaseConnectionPool.cleanup() | ||
|