Merge lp:~stub/launchpad/feed-end-at into lp:launchpad

Proposed by Stuart Bishop
Status: Merged
Merged at revision: 17514
Proposed branch: lp:~stub/launchpad/feed-end-at
Merge into: lp:launchpad
Diff against target: 35 lines (+13/-1)
1 file modified
cronscripts/librarian-feed-swift.py (+13/-1)
To merge this branch: bzr merge lp:~stub/launchpad/feed-end-at
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+259378@code.launchpad.net

Commit message

[stub, r=wgrant][noqa] Add an option to librarian-feed-swift.py allowing us to not process newer files.

Description of the change

Add an option to librarian-feed-swift.py allowing us to not process newer files.

The goal is to ensure that we have at least two copies of Librarian data in two different systems (disk & swift, or swift & offsite backup). By running two jobs in sequence, the first moving all disk files into Swift older than $cutoff, and the second copying all disk files into Swift younger than $cutoff, we create a window where data exists both on disk and in Swift. Our other systems can ensure that the data is mirrored from Swift to offsite during that window.

The alternative approach would be a single run, and providing a new option to not remove files younger than $cutoff. This would be better, but less of a quick and easy fix.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'cronscripts/librarian-feed-swift.py'
2--- cronscripts/librarian-feed-swift.py 2014-12-16 09:20:15 +0000
3+++ cronscripts/librarian-feed-swift.py 2015-05-18 13:30:47 +0000
4@@ -35,11 +35,16 @@
5 self.parser.add_option(
6 "--start-since", action="store", dest='start_since',
7 default=None, metavar="INTERVAL",
8- help="Migrate files starting from INTERVAL (PostgreSQL syntax)")
9+ help="Migrate files older than INTERVAL (PostgreSQL syntax)")
10 self.parser.add_option(
11 "-e", "--end", action="store", type=int, default=None,
12 dest="end", metavar="CONTENT_ID",
13 help="Migrate files up to and including CONTENT_ID")
14+ self.parser.add_option(
15+ "--end-at", action="store", dest='end_at',
16+ default=None, metavar="INTERVAL",
17+ help="Don't migrate files older than INTERVAL "
18+ "(PostgreSQL syntax)")
19
20 def main(self):
21 if self.options.rename and self.options.remove:
22@@ -58,6 +63,13 @@
23 - CAST(%s AS INTERVAL)
24 """, (unicode(self.options.start_since),)).get_one()[0]
25
26+ if self.options.end_at:
27+ self.options.end = ISlaveStore(LibraryFileContent).execute("""
28+ SELECT MAX(id) FROM LibraryFileContent
29+ WHERE datecreated < current_timestamp at time zone 'UTC'
30+ - CAST(%s AS INTERVAL)
31+ """, (unicode(self.options.end_at),)).get_one()[0]
32+
33 if self.options.ids and (self.options.start or self.options.end):
34 self.parser.error(
35 "Cannot specify both individual file(s) and range")