8383
8484POSTPROCESS_QUEUE = 'postprocess'
8585UTASK_MAINS_QUEUE = 'utask_main'
86+ PREPROCESS_QUEUE = 'preprocess'
8687
8788# See https://github.com/google/clusterfuzz/issues/3347 for usage
8889SUBQUEUE_IDENTIFIER = ':'
@@ -281,8 +282,7 @@ def is_done_collecting_messages():
281282def get_postprocess_task ():
282283 """Gets a postprocess task if one exists."""
283284 # This should only be run on non-preemptible bots.
284- if not (task_utils .is_remotely_executing_utasks () or
285- task_utils .get_opted_in_tasks ()):
285+ if not task_utils .is_remotely_executing_utasks ():
286286 return None
287287 # Postprocess is platform-agnostic, so we run all such tasks on our
288288 # most generic and plentiful bots only. In other words, we avoid
@@ -304,9 +304,29 @@ def allow_all_tasks():
304304 return not environment .get_value ('PREEMPTIBLE' )
305305
306306
307+ def get_preprocess_task ():
308+ pubsub_puller = PubSubPuller (PREPROCESS_QUEUE )
309+ messages = pubsub_puller .get_messages (max_messages = 1 )
310+ if not messages :
311+ return None
312+ task = get_task_from_message (messages [0 ])
313+ if task :
314+ logs .info ('Pulled from preprocess queue.' )
315+ return task
316+
317+
318+ def tworker_get_task ():
319+ assert environment .is_tworker ()
320+ task = get_postprocess_task ()
321+ if task :
322+ return task
323+
324+ return get_preprocess_task ()
325+
326+
307327def get_task ():
308- """Returns an ordinary (non-postprocess, non- utask_main) task that is pulled
309- from a ClusterFuzz task queue."""
328+ """Returns an ordinary (non-utask_main) task that is pulled from a ClusterFuzz
329+ task queue."""
310330 task = get_command_override ()
311331 if task :
312332 return task
@@ -319,6 +339,7 @@ def get_task():
319339 task = get_postprocess_task ()
320340 if task :
321341 return task
342+
322343 # Check the high-end jobs queue for bots with multiplier greater than 1.
323344 thread_multiplier = environment .get_value ('THREAD_MULTIPLIER' )
324345 if thread_multiplier and thread_multiplier > 1 :
@@ -368,8 +389,7 @@ def __init__(self,
368389 eta = None ,
369390 is_command_override = False ,
370391 high_end = False ,
371- extra_info = None ,
372- is_from_queue = False ):
392+ extra_info = None ):
373393 self .command = command
374394 self .argument = argument
375395 self .job = job
@@ -378,16 +398,6 @@ def __init__(self,
378398 self .high_end = high_end
379399 self .extra_info = extra_info
380400
381- # is_from_queue is a temporary hack to keep track of which fuzz tasks came
382- # from the queue. Previously all fuzz tasks were picked by the bot when
383- # there was nothing on the queue. With the rearchitecture, we want fuzz
384- # tasks that were put on the queue by the schedule_fuzz cron job to be
385- # executed on batch. is_from_queue is used to do this.
386- # TODO(b/378684001): This code is very ugly, get rid of it when no more
387- # fuzz tasks are executed on the bots themselves (i.e. when the rearch
388- # is complete).
389- self .is_from_queue = is_from_queue
390-
391401 def __repr__ (self ):
392402 return f'Task: { self .command } { self .argument } { self .job } '
393403
@@ -428,13 +438,11 @@ def lease(self):
428438class PubSubTask (Task ):
429439 """A Pub/Sub task."""
430440
431- def __init__ (self , pubsub_message , is_from_queue = False ):
441+ def __init__ (self , pubsub_message ):
432442 self ._pubsub_message = pubsub_message
433443 super ().__init__ (
434- self .attribute ('command' ),
435- self .attribute ('argument' ),
436- self .attribute ('job' ),
437- is_from_queue = is_from_queue )
444+ self .attribute ('command' ), self .attribute ('argument' ),
445+ self .attribute ('job' ))
438446
439447 self .extra_info = {
440448 key : value
@@ -540,7 +548,7 @@ def initialize_task(message) -> PubSubTask:
540548 """Creates a task from |messages|."""
541549
542550 if message .attributes .get ('eventType' ) != 'OBJECT_FINALIZE' :
543- return PubSubTask (message , is_from_queue = True )
551+ return PubSubTask (message )
544552
545553 # Handle postprocess task.
546554 # The GCS API for pub/sub notifications uses the data field unlike
@@ -549,7 +557,7 @@ def initialize_task(message) -> PubSubTask:
549557 name = data ['name' ]
550558 bucket = data ['bucket' ]
551559 output_url_argument = storage .get_cloud_storage_file_path (bucket , name )
552- return PostprocessPubSubTask (output_url_argument , message , is_from_queue = True )
560+ return PostprocessPubSubTask (output_url_argument , message )
553561
554562
555563class PostprocessPubSubTask (PubSubTask ):
@@ -558,21 +566,14 @@ class PostprocessPubSubTask(PubSubTask):
558566 def __init__ (self ,
559567 output_url_argument ,
560568 pubsub_message ,
561- is_command_override = False ,
562- is_from_queue = False ):
569+ is_command_override = False ):
563570 command = 'postprocess'
564571 job_type = 'none'
565572 eta = None
566573 high_end = False
567574 grandparent_class = super (PubSubTask , self )
568- grandparent_class .__init__ (
569- command ,
570- output_url_argument ,
571- job_type ,
572- eta ,
573- is_command_override ,
574- high_end ,
575- is_from_queue = is_from_queue )
575+ grandparent_class .__init__ (command , output_url_argument , job_type , eta ,
576+ is_command_override , high_end )
576577 self ._pubsub_message = pubsub_message
577578
578579
0 commit comments