docstr: The schedule method is used to run a part of the flow logic on timely manner.
  
  .. code-block:: python
  
      from lightning.app import LightningFlow
  
  
      class Flow(LightningFlow):
          def run(self):
              if self.schedule("hourly"):
                  print("run some code every hour")
  
  Arguments:
      cron_pattern: The cron pattern to provide. Learn more at https://crontab.guru/.
      start_time: The start time of the cron job.
      user_key: Optional key used to improve the caching mechanism.
  
  A best practice is to avoid running a dynamic flow or work under the self.schedule method.
  Instead, instantiate them within the condition, but run them outside.
  
  .. code-block:: python
  
      from lightning.app import LightningFlow
      from lightning.app.structures import List
  
  
      class SchedulerDAG(LightningFlow):
          def __init__(self):
              super().__init__()
              self.dags = List()
  
          def run(self):
              if self.schedule("hourly"):
                  self.dags.append(DAG(...))
  
              for dag in self.dags:
                  payload = dag.run()
  
  **Learn more about Scheduling**
  
  .. raw:: html
  
      <div class="display-card-container">
          <div class="row">
  
  .. displayitem::
      :header: Schedule your components
      :description: Learn more scheduling.
      :col_css: col-md-4
      :button_link: ../../../glossary/scheduling.html
      :height: 180
      :tag: Basic
  
  .. displayitem::
      :header: Build your own DAG
      :description: Learn more DAG scheduling with examples.
      :col_css: col-md-4
      :button_link: ../../../examples/app/dag/dag.html
      :height: 180
      :tag: Basic
  
  .. raw:: html
  
          </div>
      </div>
      <br />
docstr_tok: ["The","schedule","method","is","used","to","run","a","part","of","the","flow","logic","on","timely","manner",".","..","code-block",":",":","python","from","lightning.app","import","LightningFlow","class","Flow","(","LightningFlow",")",":","def","run","(","self",")",":","if","self.schedule","(","``","hourly","''",")",":","print","(","``","run","some","code","every","hour","''",")","Arguments",":","cron_pattern",":","The","cron","pattern","to","provide",".","Learn","more","at","https",":","\/\/crontab.guru\/",".","start_time",":","The","start","time","of","the","cron","job",".","user_key",":","Optional","key","used","to","improve","the","caching","mechanism",".","A","best","practice","is","to","avoid","running","a","dynamic","flow","or","work","under","the","self.schedule","method",".","Instead",",","instantiate","them","within","the","condition",",","but","run","them","outside",".","..","code-block",":",":","python","from","lightning.app","import","LightningFlow","from","lightning.app.structures","import","List","class","SchedulerDAG","(","LightningFlow",")",":","def","__init__","(","self",")",":","super","(",")",".__init__","(",")","self.dags","=","List","(",")","def","run","(","self",")",":","if","self.schedule","(","``","hourly","''",")",":","self.dags.append","(","DAG","(","...",")",")","for","dag","in","self.dags",":","payload","=","dag.run","(",")","*","*","Learn","more","about","Scheduling","*","*","..","raw",":",":","html","<","div","class=","''","display-card-container","''",">","<","div","class=","''","row","''",">","..","displayitem",":",":",":","header",":","Schedule","your","components",":","description",":","Learn","more","scheduling",".",":","col_css",":","col-md-4",":","button_link",":","..","\/","..","\/","..","\/glossary\/scheduling.html",":","height",":","180",":","tag",":","Basic","..","displayitem",":",":",":","header",":","Build","your","own","DAG",":","description",":","Learn","more","DAG","scheduling","with","examples",".",":","col_css",":","col-md-4",":","button_link",":","..","\/","..","\/","..","\/examples\/app\/dag\/dag.html",":","height",":","180",":","tag",":","Basic","..","raw",":",":","html","<","\/div",">","<","\/div",">","<","br","\/",">"]
code: def schedule(
      self,
      cron_pattern: str,
      start_time: Optional[datetime] = None,
      user_key: Optional[str] = None,
  ) -> bool:
      """The schedule method is used to run a part of the flow logic on timely manner.
  
      .. code-block:: python
  
          from lightning.app import LightningFlow
  
  
          class Flow(LightningFlow):
              def run(self):
                  if self.schedule("hourly"):
                      print("run some code every hour")
  
      Arguments:
          cron_pattern: The cron pattern to provide. Learn more at https://crontab.guru/.
          start_time: The start time of the cron job.
          user_key: Optional key used to improve the caching mechanism.
  
      A best practice is to avoid running a dynamic flow or work under the self.schedule method.
      Instead, instantiate them within the condition, but run them outside.
  
      .. code-block:: python
  
          from lightning.app import LightningFlow
          from lightning.app.structures import List
  
  
          class SchedulerDAG(LightningFlow):
              def __init__(self):
                  super().__init__()
                  self.dags = List()
  
              def run(self):
                  if self.schedule("hourly"):
                      self.dags.append(DAG(...))
  
                  for dag in self.dags:
                      payload = dag.run()
  
      **Learn more about Scheduling**
  
      .. raw:: html
  
          <div class="display-card-container">
              <div class="row">
  
      .. displayitem::
          :header: Schedule your components
          :description: Learn more scheduling.
          :col_css: col-md-4
          :button_link: ../../../glossary/scheduling.html
          :height: 180
          :tag: Basic
  
      .. displayitem::
          :header: Build your own DAG
          :description: Learn more DAG scheduling with examples.
          :col_css: col-md-4
          :button_link: ../../../examples/app/dag/dag.html
          :height: 180
          :tag: Basic
  
      .. raw:: html
  
              </div>
          </div>
          <br />
  
      """
      if not user_key:
          frame = cast(FrameType, inspect.currentframe()).f_back
          assert frame is not None
          cache_key = f"{cron_pattern}.{frame.f_code.co_filename}.{frame.f_lineno}"
      else:
          cache_key = user_key
  
      call_hash = (
          f"{self.schedule.__name__}:{DeepHash(cache_key)[cache_key]}"
      )
  
      if "scheduling" not in self._calls:
          self._calls["scheduling"] = {}
  
      entered = call_hash in self._calls["scheduling"]
  
      expr_aliases = {
          "midnight": "@midnight",
          "hourly": "@hourly",
          "daily": "@daily",
          "weekly": "@weekly",
          "monthly": "@monthly",
          "yearly": "@yearly",
          "annually": "@annually",
      }
  
      if cron_pattern in expr_aliases:
          cron_pattern = expr_aliases[cron_pattern]
  
      if not entered:
          if not start_time:
              start_time = datetime.now()
  
          schedule_metadata = {
              "running": False,
              "cron_pattern": cron_pattern,
              "start_time": str(start_time.isoformat()),
              "name": self.name,
          }
  
          self._calls["scheduling"][call_hash] = schedule_metadata
          app = _LightningAppRef().get_current()
          if app:
              app._register_schedule(call_hash, schedule_metadata)
          return True
  
      return self._calls["scheduling"][call_hash]["running"]
  
imports: import inspect
  import warnings
  from copy import deepcopy
  from datetime import datetime
  from types import FrameType
  from typing import TYPE_CHECKING, Any, Dict, Generator, Iterable, List, Optional, Tuple, Union, cast
  from deepdiff import DeepHash
  from lightning.app.core.work import LightningWork
  from lightning.app.frontend import Frontend
  from lightning.app.storage.drive import Drive, _maybe_create_drive
  from lightning.app.storage.path import Path
  from lightning.app.utilities.app_helpers import _is_json_serializable, _LightningAppRef, _set_child_name, is_overridden
  from lightning.app.utilities.component import _sanitize_state
  from lightning.app.utilities.exceptions import ExitAppException, LightningFlowException
  from lightning.app.utilities.introspection import _is_init_context, _is_run_context
  from lightning.app.utilities.packaging.cloud_compute import CloudCompute, _maybe_create_cloud_compute
label_desc: Use image node_id 22 for calling the LightningFlow obj's underlying member method code with example usage: obj.schedule(cron_pattern, start_time, user_key) and returns: self, True