omnata-plugin-runtime 0.3.23a69__py3-none-any.whl → 0.3.24a71__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -1823,30 +1823,40 @@ def managed_outbound_processing(concurrency: int, batch_size: int):
1823
1823
  def actual_decorator(method):
1824
1824
  @wraps(method)
1825
1825
  def _impl(self: OmnataPlugin, *method_args, **method_kwargs):
1826
+ logger.info(f"managed_outbound_processing invoked with {len(method_args)} positional arguments and {len(method_kwargs)} named arguments ({','.join(method_kwargs.keys())})")
1826
1827
  if self._sync_request is None: # pylint: disable=protected-access
1827
1828
  raise ValueError(
1828
1829
  "To use the managed_outbound_processing decorator, you must attach a sync request to the plugin instance (via the _sync_request property)"
1829
1830
  )
1830
- # if self._sync_request.api_limits is None:
1831
- # raise ValueError('To use the managed_outbound_processing decorator, API constraints must be defined. These can be provided in the response to the connect method')
1832
1831
  logger.info(f"Batch size: {batch_size}. Concurrency: {concurrency}")
1833
- if len(method_args) == 0:
1834
- raise ValueError(
1835
- "You must provide at least one method argument, and the first argument must be a DataFrame or DataFrame generator (from outbound_sync_request.get_records)"
1836
- )
1837
- first_arg = method_args[0]
1838
- #logger.info(first_arg.__class__.__name__)
1839
- if first_arg.__class__.__name__ == "DataFrame":
1840
- logger.info("managed_outbound_processing received a DataFrame")
1841
- elif hasattr(first_arg, "__next__"):
1842
- logger.info("managed_outbound_processing received an iterator function")
1843
- else:
1844
- raise ValueError(
1845
- f"The first argument to a @managed_outbound_processing method must be a DataFrame or DataFrame generator (from outbound_sync_request.get_records). Instead, a {first_arg.__class__.__name__} was provided."
1846
- )
1832
+
1833
+ dataframe_arg = None
1834
+ if 'dataframe' in method_kwargs:
1835
+ dataframe_arg = method_kwargs['dataframe']
1836
+ del method_kwargs['dataframe']
1837
+ if dataframe_arg.__class__.__name__ != "DataFrame":
1838
+ raise ValueError(
1839
+ f"The 'dataframe' named argument to the @managed_outbound_processing must be a DataFrame. Instead, a {dataframe_arg.__class__.__name__} was provided."
1840
+ )
1841
+
1842
+ elif 'dataframe_generator' in method_kwargs:
1843
+ dataframe_arg = method_kwargs['dataframe_generator']
1844
+ del method_kwargs['dataframe_generator']
1845
+ if not hasattr(dataframe_arg, "__next__"):
1846
+ raise ValueError(
1847
+ f"The 'dataframe_generator' named argument to the @managed_outbound_processing must be an iterator function. Instead, a {dataframe_arg.__class__.__name__} was provided."
1848
+ )
1849
+ # if the dataframe was provided as the first argument, we'll use that
1850
+ if dataframe_arg is None and len(method_args) > 0:
1851
+ dataframe_arg = method_args[0]
1852
+ if dataframe_arg.__class__.__name__ != "DataFrame" and not hasattr(dataframe_arg, "__next__"):
1853
+ raise ValueError(
1854
+ f"The first argument to a @managed_outbound_processing method must be a DataFrame or DataFrame generator (from outbound_sync_request.get_records). Instead, a {first_arg.__class__.__name__} was provided. Alternatively, you can provide these via the 'dataframe' or 'dataframe_generator' named arguments."
1855
+ )
1856
+ method_args = method_args[1:]
1847
1857
 
1848
1858
  # put the record iterator on the queue, ready for the first task to read it
1849
- fixed_size_generator = FixedSizeGenerator(first_arg, batch_size=batch_size)
1859
+ fixed_size_generator = FixedSizeGenerator(dataframe_arg, batch_size=batch_size)
1850
1860
  tasks:List[threading.Thread] = []
1851
1861
  logger.info(f"Creating {concurrency} worker(s) for applying records")
1852
1862
  # just in case
@@ -1862,7 +1872,7 @@ def managed_outbound_processing(concurrency: int, batch_size: int):
1862
1872
  i,
1863
1873
  fixed_size_generator,
1864
1874
  self._sync_request._thread_cancellation_token,
1865
- method_args[1:],
1875
+ method_args,
1866
1876
  method_kwargs,
1867
1877
  ),
1868
1878
  )
@@ -1982,27 +1992,26 @@ def managed_inbound_processing(concurrency: int):
1982
1992
  raise ValueError(
1983
1993
  "To use the managed_inbound_processing decorator, you must attach an apply request to the plugin instance (via the _sync_request property)"
1984
1994
  )
1985
-
1995
+ logger.info(f"managed_inbound_processing invoked with {len(method_args)} positional arguments and {len(method_kwargs)} named arguments ({','.join(method_kwargs.keys())})")
1986
1996
  if self._sync_request.development_mode is True:
1987
1997
  concurrency_to_use = 1 # disable concurrency when running in development mode, it interferes with pyvcr
1988
1998
  else:
1989
1999
  concurrency_to_use = concurrency
1990
- # if self._sync_request.api_limits is None:
1991
- # raise ValueError('To use the managed_inbound_processing decorator, API constraints must be defined. These can be provided in the response to the connect method')
1992
- if len(method_args) == 0:
1993
- raise ValueError(
1994
- "You must provide at least one method argument, and the first argument must be a list of StoredStreamConfigurations (from inbound_sync_request.streams)"
1995
- )
1996
- first_arg: List[StoredStreamConfiguration] = method_args[0]
1997
- logger.info(first_arg.__class__.__name__)
1998
- if first_arg.__class__.__name__ == "list":
1999
- logger.info("managed_inbound_processing received a list")
2000
- else:
2001
- raise ValueError(
2002
- f"The first argument to a @managed_inbound_processing method must be a list of StoredStreamConfigurations. Instead, a {first_arg.__class__.__name__} was provided."
2003
- )
2000
+ stream_list_arg: List[StoredStreamConfiguration] = None
2001
+ if 'streams' in method_kwargs:
2002
+ stream_list_arg = cast(List[StoredStreamConfiguration],method_kwargs['streams'])
2003
+ del method_kwargs['streams']
2004
+ if stream_list_arg is None and len(method_args) > 0:
2005
+ stream_list_arg = cast(List[StoredStreamConfiguration],method_args[0])
2006
+ if stream_list_arg.__class__.__name__ != "list":
2007
+ raise ValueError(
2008
+ f"The first argument to a @managed_inbound_processing method must be a list of StoredStreamConfigurations if the 'streams' named argument is not provided. Instead, a {stream_list_arg.__class__.__name__} was provided."
2009
+ )
2010
+ method_args = method_args[1:]
2011
+ if stream_list_arg is None:
2012
+ raise ValueError("You must provide a list of StoredStreamConfiguration objects to the method, either as the first argument or as a named argument 'streams'")
2004
2013
 
2005
- streams_list: List[StoredStreamConfiguration] = first_arg
2014
+ streams_list = stream_list_arg
2006
2015
  # create a queue full of all the streams to process
2007
2016
  streams_queue = queue.Queue()
2008
2017
  for stream in streams_list:
@@ -2022,7 +2031,7 @@ def managed_inbound_processing(concurrency: int):
2022
2031
  i,
2023
2032
  streams_queue,
2024
2033
  self._sync_request._thread_cancellation_token,
2025
- method_args[1:],
2034
+ method_args,
2026
2035
  method_kwargs,
2027
2036
  ),
2028
2037
  )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: omnata-plugin-runtime
3
- Version: 0.3.23a69
3
+ Version: 0.3.24a71
4
4
  Summary: Classes and common runtime components for building and running Omnata Plugins
5
5
  Author: James Weakley
6
6
  Author-email: james.weakley@omnata.com
@@ -3,10 +3,10 @@ omnata_plugin_runtime/api.py,sha256=_N5ok5LN7GDO4J9n3yduXp3tpjmhpySY__U2baiygrs,
3
3
  omnata_plugin_runtime/configuration.py,sha256=7cMekoY8CeZAJHpASU6tCMidF55Hzfr7CD74jtebqIY,35742
4
4
  omnata_plugin_runtime/forms.py,sha256=pw_aKVsXSz47EP8PFBI3VDwdSN5IjvZxp8JTjO1V130,18421
5
5
  omnata_plugin_runtime/logging.py,sha256=bn7eKoNWvtuyTk7RTwBS9UARMtqkiICtgMtzq3KA2V0,3272
6
- omnata_plugin_runtime/omnata_plugin.py,sha256=EaGIQdq_gcmH2loTluTa0T3YxuUhDNZTQIItzYXtZxE,102783
6
+ omnata_plugin_runtime/omnata_plugin.py,sha256=rqtkS1xJeOhtmC6HgxjGU3to-riXV0pfO2AoK4Oj1us,103702
7
7
  omnata_plugin_runtime/plugin_entrypoints.py,sha256=s-SrUnXaS6FaBq1igiJhcCB3Md_a6op-dp_g1H_55QU,27736
8
8
  omnata_plugin_runtime/rate_limiting.py,sha256=se6MftQI5NrVHaLb1hByPCgAESPQhkAgIG7KIU1clDU,16562
9
- omnata_plugin_runtime-0.3.23a69.dist-info/LICENSE,sha256=IMF9i4xIpgCADf0U-V1cuf9HBmqWQd3qtI3FSuyW4zE,26526
10
- omnata_plugin_runtime-0.3.23a69.dist-info/METADATA,sha256=u_HhdrNMZOCVn0A9Lv-u9q3KnOmxvRlJLDFAHrU8si0,1604
11
- omnata_plugin_runtime-0.3.23a69.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
12
- omnata_plugin_runtime-0.3.23a69.dist-info/RECORD,,
9
+ omnata_plugin_runtime-0.3.24a71.dist-info/LICENSE,sha256=IMF9i4xIpgCADf0U-V1cuf9HBmqWQd3qtI3FSuyW4zE,26526
10
+ omnata_plugin_runtime-0.3.24a71.dist-info/METADATA,sha256=2uATfstzzcn6LDYKI6dGaHvITjwx_659FuvbM4aAEfk,1604
11
+ omnata_plugin_runtime-0.3.24a71.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
12
+ omnata_plugin_runtime-0.3.24a71.dist-info/RECORD,,