1616 bootstrap ,
1717 chunk_id_str ,
1818 print_completion_rate ,
19- print_ingest_status ,
19+ print_status ,
2020 queue_layer_helper ,
21+ job_type_guard ,
2122)
2223from .simple_tests import run_all
2324from .create .parent_layer import add_parent_chunk
2425from ..graph .chunkedgraph import ChunkedGraph
2526from ..utils .redis import get_redis_connection , keys as r_keys
2627
27- ingest_cli = AppGroup ("ingest" )
28+ group_name = "ingest"
29+ ingest_cli = AppGroup (group_name )
2830
2931
3032def init_ingest_cmds (app ):
3133 app .cli .add_command (ingest_cli )
3234
3335
3436@ingest_cli .command ("flush_redis" )
37+ @click .confirmation_option (prompt = "Are you sure you want to flush redis?" )
38+ @job_type_guard (group_name )
3539def flush_redis ():
3640 """FLush redis db."""
3741 redis = get_redis_connection ()
@@ -44,13 +48,16 @@ def flush_redis():
4448@click .option ("--raw" , is_flag = True , help = "Read edges from agglomeration output." )
4549@click .option ("--test" , is_flag = True , help = "Test 8 chunks at the center of dataset." )
4650@click .option ("--retry" , is_flag = True , help = "Rerun without creating a new table." )
51+ @job_type_guard (group_name )
4752def ingest_graph (
4853 graph_id : str , dataset : click .Path , raw : bool , test : bool , retry : bool
4954):
5055 """
5156 Main ingest command.
5257 Takes ingest config from a yaml file and queues atomic tasks.
5358 """
59+ redis = get_redis_connection ()
60+ redis .set (r_keys .JOB_TYPE , group_name )
5461 with open (dataset , "r" ) as stream :
5562 config = yaml .safe_load (stream )
5663
@@ -70,6 +77,7 @@ def ingest_graph(
7077@click .argument ("graph_id" , type = str )
7178@click .argument ("dataset" , type = click .Path (exists = True ))
7279@click .option ("--raw" , is_flag = True )
80+ @job_type_guard (group_name )
7381def pickle_imanager (graph_id : str , dataset : click .Path , raw : bool ):
7482 """
7583 Load ingest config into redis server.
@@ -83,11 +91,12 @@ def pickle_imanager(graph_id: str, dataset: click.Path, raw: bool):
8391
8492 meta , ingest_config , _ = bootstrap (graph_id , config = config , raw = raw )
8593 imanager = IngestionManager (ingest_config , meta )
86- imanager .redis # pylint: disable=pointless-statement
94+ imanager .redis . set ( r_keys . JOB_TYPE , group_name )
8795
8896
8997@ingest_cli .command ("layer" )
9098@click .argument ("parent_layer" , type = int )
99+ @job_type_guard (group_name )
91100def queue_layer (parent_layer ):
92101 """
93102 Queue all chunk tasks at a given layer.
@@ -100,16 +109,21 @@ def queue_layer(parent_layer):
100109
101110
102111@ingest_cli .command ("status" )
112+ @job_type_guard (group_name )
103113def ingest_status ():
104114 """Print ingest status to console by layer."""
105115 redis = get_redis_connection ()
106- imanager = IngestionManager .from_pickle (redis .get (r_keys .INGESTION_MANAGER ))
107- print_ingest_status (imanager , redis )
116+ try :
117+ imanager = IngestionManager .from_pickle (redis .get (r_keys .INGESTION_MANAGER ))
118+ print_status (imanager , redis )
119+ except TypeError as err :
120+ print (f"\n No current `{ group_name } ` job found in redis: { err } " )
108121
109122
110123@ingest_cli .command ("chunk" )
111124@click .argument ("queue" , type = str )
112125@click .argument ("chunk_info" , nargs = 4 , type = int )
126+ @job_type_guard (group_name )
113127def ingest_chunk (queue : str , chunk_info ):
114128 """Manually queue chunk when a job is stuck for whatever reason."""
115129 redis = get_redis_connection ()
@@ -135,6 +149,7 @@ def ingest_chunk(queue: str, chunk_info):
135149@click .argument ("graph_id" , type = str )
136150@click .argument ("chunk_info" , nargs = 4 , type = int )
137151@click .option ("--n_threads" , type = int , default = 1 )
152+ @job_type_guard (group_name )
138153def ingest_chunk_local (graph_id : str , chunk_info , n_threads : int ):
139154 """Manually ingest a chunk on a local machine."""
140155 layer , coords = chunk_info [0 ], chunk_info [1 :]
@@ -150,6 +165,7 @@ def ingest_chunk_local(graph_id: str, chunk_info, n_threads: int):
150165@ingest_cli .command ("rate" )
151166@click .argument ("layer" , type = int )
152167@click .option ("--span" , default = 10 , help = "Time span to calculate rate." )
168+ @job_type_guard (group_name )
153169def rate (layer : int , span : int ):
154170 redis = get_redis_connection ()
155171 imanager = IngestionManager .from_pickle (redis .get (r_keys .INGESTION_MANAGER ))
@@ -158,5 +174,6 @@ def rate(layer: int, span: int):
158174
159175@ingest_cli .command ("run_tests" )
160176@click .argument ("graph_id" , type = str )
177+ @job_type_guard (group_name )
161178def run_tests (graph_id ):
162179 run_all (ChunkedGraph (graph_id = graph_id ))
0 commit comments