55from ..base import _InternalProgram , ProgramRunning , ProgramSuccess
66from apsis .lib .json import check_schema , nkey
77from apsis .lib .parse import parse_duration
8+ from apsis .lib .timing import Timer
89from apsis .runs import template_expand
910
1011log = logging .getLogger (__name__ )
@@ -104,9 +105,13 @@ async def wait(self, apsis):
104105
105106 row_counts = {}
106107 meta = {
107- "run count" : 0 ,
108- "run_ids" : [],
109- "row counts" : row_counts
108+ "run count" : 0 ,
109+ "run_ids" : [],
110+ "row counts" : row_counts ,
111+ "time" : {
112+ "get runs" : 0 ,
113+ "archive runs" : 0 ,
114+ }
110115 }
111116
112117 count = self .__count
@@ -115,31 +120,32 @@ async def wait(self, apsis):
115120 count if self .__chunk_size is None
116121 else min (count , self .__chunk_size )
117122 )
118- run_ids = db .get_archive_run_ids (
119- before = ora .now () - self .__age ,
120- count = chunk ,
121- )
123+ with Timer () as timer :
124+ run_ids = db .get_archive_run_ids (
125+ before = ora .now () - self .__age ,
126+ count = chunk ,
127+ )
128+ meta ["time" ]["get runs" ] += timer .elapsed
122129 count -= chunk
123130
124131 # Make sure all runs are retired; else skip them.
125132 run_ids = [ r for r in run_ids if apsis .run_store .retire (r ) ]
126133
127134 if len (run_ids ) > 0 :
128135 # Archive these runs.
129- chunk_row_counts = db .archive (self .__path , run_ids )
136+ with Timer () as timer :
137+ chunk_row_counts = db .archive (self .__path , run_ids )
130138 # Accumulate metadata.
131139 meta ["run count" ] += len (run_ids )
132140 meta ["run_ids" ].append (run_ids )
133141 for key , value in chunk_row_counts .items ():
134142 row_counts [key ] = row_counts .get (key , 0 ) + value
143+ meta ["time" ]["archive runs" ] += timer .elapsed
135144
136145 if count > 0 and self .__chunk_sleep is not None :
137146 # Yield to the event loop.
138147 await asyncio .sleep (self .__chunk_sleep )
139148
140- # Also vacuum to free space.
141- db .vacuum ()
142-
143149 return ProgramSuccess (meta = meta )
144150
145151
0 commit comments