File: model_execution_scheduler.h

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (64 lines) | stat: -rw-r--r-- 2,723 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_SEGMENTATION_PLATFORM_INTERNAL_SCHEDULER_MODEL_EXECUTION_SCHEDULER_H_
#define COMPONENTS_SEGMENTATION_PLATFORM_INTERNAL_SCHEDULER_MODEL_EXECUTION_SCHEDULER_H_

#include "components/segmentation_platform/public/proto/segmentation_platform.pb.h"

namespace segmentation_platform {
namespace proto {
class SegmentInfo;
}  // namespace proto

struct ModelExecutionResult;

using proto::SegmentId;

// Central class responsible for scheduling model execution. Determines which
// models are eligible for execution based on various criteria e.g. cached
// results, TTL etc. Invoked from multiple classes such as segment
// selector or periodic jobs.
class ModelExecutionScheduler {
 public:
  // An observer to be notified about the model execution and results.
  class Observer {
   public:
    // Called whenever a model execution completes.
    virtual void OnModelExecutionCompleted(SegmentId segment_id) = 0;
  };

  virtual ~ModelExecutionScheduler() = default;

  // Called whenever a new or updated model is available. Must be a valid
  // SegmentInfo with valid metadata and features.
  virtual void OnNewModelInfoReady(const proto::SegmentInfo& segment_info) = 0;

  // Central method to determine which all models to execute. Called in response
  // to segmentation requests from clients, or periodic tasks. Can be called
  // repeatedly. Loops through all the models and decides whether to execute a
  // model or not. A segment is considered eligible to run based on
  // - if it has no results, or
  // - if the results have expired or
  // - if the results weren't computed too recently, and |expired_only| is false
  // - if all the required signals have been collected for sufficient duration.
  virtual void RequestModelExecutionForEligibleSegments(bool expired_only) = 0;

  // Runs model execution for a particular segment.
  virtual void RequestModelExecution(
      const proto::SegmentInfo& segment_info) = 0;

  // Called after model execution completes. If the execution was successful,
  // saves the results to the DB, and notifies observers. If the execution was
  // unsuccessful, deletes the result from the DB.
  // TODO(shaktisahu): Do we want to store that failure reason in the DB
  // instead? We might treat different failures differently next time.
  virtual void OnModelExecutionCompleted(
      const proto::SegmentInfo& segment_info,
      std::unique_ptr<ModelExecutionResult> result) = 0;
};

}  // namespace segmentation_platform

#endif  // COMPONENTS_SEGMENTATION_PLATFORM_INTERNAL_SCHEDULER_MODEL_EXECUTION_SCHEDULER_H_