tester.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. package plugin_manager
  2. /*
  3. NOTE: tester is deprecated, maybe, in several months, we will support this again
  4. */
  5. // func (p *PluginManager) TestPlugin(
  6. // path string,
  7. // request map[string]any,
  8. // access_type access_types.PluginAccessType,
  9. // access_action access_types.PluginAccessAction,
  10. // timeout string,
  11. // ) (*stream.Stream[any], error) {
  12. // // launch plugin runtime
  13. // plugin, err := p.getLocalPluginRuntime(path)
  14. // if err != nil {
  15. // return nil, errors.Join(err, errors.New("failed to load plugin"))
  16. // }
  17. // // get assets
  18. // assets, err := plugin.decoder.Assets()
  19. // if err != nil {
  20. // return nil, errors.Join(err, errors.New("failed to get assets"))
  21. // }
  22. // local_plugin_runtime := local_runtime.NewLocalPluginRuntime(p.pythonInterpreterPath)
  23. // local_plugin_runtime.PluginRuntime = plugin.runtime
  24. // local_plugin_runtime.PositivePluginRuntime = positive_manager.PositivePluginRuntime{
  25. // BasicPluginRuntime: basic_runtime.NewBasicPluginRuntime(p.mediaBucket),
  26. // WorkingPath: plugin.runtime.State.WorkingPath,
  27. // Decoder: plugin.decoder,
  28. // }
  29. // if err := local_plugin_runtime.RemapAssets(
  30. // &local_plugin_runtime.Config,
  31. // assets,
  32. // ); err != nil {
  33. // return nil, errors.Join(err, errors.New("failed to remap assets"))
  34. // }
  35. // identity, err := local_plugin_runtime.Identity()
  36. // if err != nil {
  37. // return nil, errors.Join(err, errors.New("failed to get identity"))
  38. // }
  39. // // local plugin
  40. // routine.Submit(func() {
  41. // defer func() {
  42. // if r := recover(); r != nil {
  43. // // print stack trace
  44. // buf := make([]byte, 1<<16)
  45. // runtime.Stack(buf, true)
  46. // log.Error("plugin runtime error: %v, stack trace: %s", r, string(buf))
  47. // }
  48. // }()
  49. // // delete the plugin from the storage when the plugin is stopped
  50. // p.fullDuplexLifecycle(local_plugin_runtime, nil)
  51. // })
  52. // // wait for the plugin to start
  53. // var timeout_duration time.Duration
  54. // if timeout == "" {
  55. // timeout_duration = 120 * time.Second
  56. // } else {
  57. // timeout_duration, err = time.ParseDuration(timeout)
  58. // if err != nil {
  59. // return nil, errors.Join(err, errors.New("failed to parse timeout"))
  60. // }
  61. // }
  62. // select {
  63. // case <-local_plugin_runtime.WaitStarted():
  64. // case <-time.After(timeout_duration):
  65. // return nil, errors.New("failed to start plugin after " + timeout_duration.String())
  66. // }
  67. // session := session_manager.NewSession(
  68. // session_manager.NewSessionPayload{
  69. // TenantID: "test-tenant",
  70. // UserID: "test-user",
  71. // PluginUniqueIdentifier: identity,
  72. // ClusterID: "test-cluster",
  73. // InvokeFrom: access_type,
  74. // Action: access_action,
  75. // Declaration: plugin.runtime.Configuration(),
  76. // BackwardsInvocation: manager.BackwardsInvocation(),
  77. // IgnoreCache: true,
  78. // },
  79. // )
  80. // session.BindRuntime(local_plugin_runtime)
  81. // defer session.Close(session_manager.CloseSessionPayload{
  82. // IgnoreCache: true,
  83. // })
  84. // // try send request
  85. // plugin_response, err := plugin_daemon.GenericInvokePlugin[map[string]any, any](session, &request, 1024)
  86. // if err != nil {
  87. // return nil, errors.Join(err, errors.New("failed to invoke plugin"))
  88. // }
  89. // plugin_response.OnClose(func() {
  90. // local_plugin_runtime.Stop()
  91. // })
  92. // return plugin_response, nil
  93. // }