# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

from crontabber.base import BaseCronApp
from crontabber.mixins import (
    with_postgres_transactions,
    with_single_postgres_transaction,
)


@with_postgres_transactions()
@with_single_postgres_transaction()
class TruncatePartitionsCronApp(BaseCronApp):
    app_name = 'truncate-partitions'
    app_version = '1.0'
    app_description = """See
    http://socorro.readthedocs.org/en/latest/databaseadminfunctions.html#truncate
    -partitions
    See https://bugzilla.mozilla.org/show_bug.cgi?id=1117911
    """

    def run(self, connection):
        # number of weeks of partitions to keep
        weeks = 2

        cursor = connection.cursor()
        # Casting to date because stored procs in psql are strongly typed.
        cursor.execute(
            "select truncate_partitions(%s)", (weeks,)
        )

@@ -193,16 +193,48 @@
 /2.0/.%0A%0A
+from configman import Namespace%0A
 from cro
@@ -744,39 +744,73 @@
 %22%22%22%0A
-%0A
     
-def run(self, connec
+required_config = Namespace()%0A    required_config.add_op
 tion
-):
+(
 %0A   
@@ -818,66 +818,144 @@
     
-# number of weeks of partitions to keep%0A        weeks = 2%0A
+'weeks_to_keep',%0A        default=2,%0A        doc='Number of weeks of raw crash data to keep in Postgres')%0A%0A    def run(self, connection):
 %0A   
@@ -1134,21 +1134,41 @@
 (%25s)%22, (
-weeks
+self.config.weeks_to_keep
 ,)%0A     

Add config option for weeks to truncate and default to 2 weeks