temporalio 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/Cargo.lock +139 -125
  3. data/README.md +90 -5
  4. data/lib/temporalio/api/batch/v1/message.rb +4 -1
  5. data/lib/temporalio/api/cloud/cloudservice/v1/request_response.rb +12 -1
  6. data/lib/temporalio/api/cloud/cloudservice/v1/service.rb +1 -1
  7. data/lib/temporalio/api/cloud/connectivityrule/v1/message.rb +29 -0
  8. data/lib/temporalio/api/cloud/identity/v1/message.rb +1 -1
  9. data/lib/temporalio/api/cloud/namespace/v1/message.rb +2 -1
  10. data/lib/temporalio/api/cloud/operation/v1/message.rb +1 -1
  11. data/lib/temporalio/api/common/v1/message.rb +2 -1
  12. data/lib/temporalio/api/enums/v1/batch_operation.rb +1 -1
  13. data/lib/temporalio/api/enums/v1/task_queue.rb +2 -1
  14. data/lib/temporalio/api/history/v1/message.rb +1 -1
  15. data/lib/temporalio/api/payload_visitor.rb +19 -1
  16. data/lib/temporalio/api/sdk/v1/worker_config.rb +23 -0
  17. data/lib/temporalio/api/taskqueue/v1/message.rb +5 -1
  18. data/lib/temporalio/api/worker/v1/message.rb +2 -1
  19. data/lib/temporalio/api/workflowservice/v1/request_response.rb +10 -1
  20. data/lib/temporalio/api/workflowservice/v1/service.rb +1 -1
  21. data/lib/temporalio/cancellation.rb +16 -12
  22. data/lib/temporalio/client/connection/cloud_service.rb +75 -0
  23. data/lib/temporalio/client/connection/workflow_service.rb +45 -0
  24. data/lib/temporalio/client/connection.rb +2 -1
  25. data/lib/temporalio/contrib/open_telemetry.rb +9 -13
  26. data/lib/temporalio/converters/payload_converter/json_plain.rb +22 -5
  27. data/lib/temporalio/internal/bridge/api/workflow_activation/workflow_activation.rb +1 -1
  28. data/lib/temporalio/internal/worker/workflow_instance/context.rb +5 -4
  29. data/lib/temporalio/internal/worker/workflow_instance/externally_immutable_hash.rb +2 -0
  30. data/lib/temporalio/internal/worker/workflow_instance/illegal_call_tracer.rb +1 -1
  31. data/lib/temporalio/internal/worker/workflow_instance/replay_safe_logger.rb +5 -2
  32. data/lib/temporalio/internal/worker/workflow_instance/scheduler.rb +10 -4
  33. data/lib/temporalio/priority.rb +47 -6
  34. data/lib/temporalio/scoped_logger.rb +1 -1
  35. data/lib/temporalio/version.rb +1 -1
  36. data/lib/temporalio/worker/illegal_workflow_call_validator.rb +9 -0
  37. data/lib/temporalio/worker.rb +10 -1
  38. data/lib/temporalio/workflow/definition.rb +4 -6
  39. data/lib/temporalio/workflow.rb +74 -3
  40. metadata +3 -1
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'random/formatter'
4
4
  require 'temporalio/error'
5
+ require 'temporalio/internal/worker/workflow_instance'
5
6
  require 'temporalio/priority'
6
7
  require 'temporalio/workflow/activity_cancellation_type'
7
8
  require 'temporalio/workflow/child_workflow_cancellation_type'
@@ -537,26 +538,72 @@ module Temporalio
537
538
  # Run a block of code with illegal call tracing disabled. Users should be cautious about using this as it can
538
539
  # often signify unsafe code.
539
540
  #
541
+ # If this is invoked outside of a workflow, it just runs the block.
542
+ #
540
543
  # @yield Block to run with call tracing disabled
541
544
  #
542
545
  # @return [Object] Result of the block.
543
546
  def self.illegal_call_tracing_disabled(&)
544
- Workflow._current.illegal_call_tracing_disabled(&)
547
+ if Workflow.in_workflow?
548
+ Workflow._current.illegal_call_tracing_disabled(&)
549
+ else
550
+ yield
551
+ end
545
552
  end
546
553
 
547
554
  # Run a block of code with IO enabled. Specifically this allows the `io_wait` call of the fiber scheduler to work.
548
555
  # Users should be cautious about using this as it can often signify unsafe code. Note, this is often only
549
556
  # applicable to network code as file IO and most process-based IO does not go through scheduler `io_wait`.
557
+ #
558
+ # If this is invoked outside of a workflow, it just runs the block.
550
559
  def self.io_enabled(&)
551
- Workflow._current.io_enabled(&)
560
+ if Workflow.in_workflow?
561
+ Workflow._current.io_enabled(&)
562
+ else
563
+ yield
564
+ end
552
565
  end
553
566
 
554
567
  # Run a block of code with the durable/deterministic workflow Fiber scheduler off. This means fallback to default
555
568
  # fiber scheduler and no workflow helpers will be available in the block. This is usually only needed in advanced
556
569
  # situations where a third party library does something like use "Timeout" in a way that shouldn't be made
557
570
  # durable.
571
+ #
572
+ # If this is invoked outside of a workflow, it just runs the block.
573
+ #
574
+ # This implies {illegal_call_tracing_disabled}.
558
575
  def self.durable_scheduler_disabled(&)
559
- Workflow._current.durable_scheduler_disabled(&)
576
+ if Workflow.in_workflow?
577
+ Workflow._current.durable_scheduler_disabled(&)
578
+ else
579
+ yield
580
+ end
581
+ end
582
+
583
+ # @!visibility private
584
+ def self._wrap_ruby_class_as_legal(target_class)
585
+ Class.new do
586
+ define_method(:initialize) do |*args, **kwargs, &block|
587
+ @underlying = Unsafe.illegal_call_tracing_disabled do
588
+ target_class.new(*args, **kwargs, &block) # steep:ignore
589
+ end
590
+ end
591
+
592
+ # @!visibility private
593
+ def method_missing(name, ...)
594
+ if @underlying.respond_to?(name)
595
+ # Call with tracing disabled
596
+ Unsafe.illegal_call_tracing_disabled { @underlying.public_send(name, ...) }
597
+ else
598
+ super
599
+ end
600
+ end
601
+
602
+ # @!visibility private
603
+ def respond_to_missing?(name, include_all = false)
604
+ @underlying.respond_to?(name, include_all) || super
605
+ end
606
+ end
560
607
  end
561
608
  end
562
609
 
@@ -623,5 +670,29 @@ module Temporalio
623
670
  # error can still be used with configuring workflow failure exception types to change non-deterministic errors from
624
671
  # task failures to workflow failures.
625
672
  class NondeterminismError < Error; end
673
+
674
+ # Mutex is a workflow-safe wrapper around {::Mutex}.
675
+ #
676
+ # As of this writing, all methods on Mutex are safe for workflow use and are implicitly made deterministic by the
677
+ # Fiber scheduler. The primary reason this is wrapped as safe is to be able to catch unintentional uses of Mutex by
678
+ # non-workflow-safe code. However, users may prefer to use the more powerful {wait_condition} approach as a mutex
679
+ # (e.g. wait until a certain attribute is set to false then set it to true before continuing).
680
+ Mutex = Unsafe._wrap_ruby_class_as_legal(::Mutex)
681
+
682
+ # Queue is a workflow-safe wrapper around {::Queue}.
683
+ #
684
+ # As of this writing, all methods on Queue are safe for workflow use and are implicitly made deterministic by the
685
+ # Fiber scheduler. The primary reason this is wrapped as safe is to be able to catch unintentional uses of Queue by
686
+ # non-workflow-safe code. However, users may prefer to use the more powerful {wait_condition} approach as a queue
687
+ # (e.g. wait until an array is non-empty before continuing).
688
+ Queue = Unsafe._wrap_ruby_class_as_legal(::Queue)
689
+
690
+ # SizedQueue is a workflow-safe wrapper around {::SizedQueue}.
691
+ #
692
+ # As of this writing, all methods on SizedQueue are safe for workflow use and are implicitly made deterministic by
693
+ # the Fiber scheduler. The primary reason this is wrapped as safe is to be able to catch unintentional uses of
694
+ # SizedQueue by non-workflow-safe code. However, users may prefer to use the more powerful {wait_condition} approach
695
+ # as a queue (e.g. wait until an array is non-empty before continuing).
696
+ SizedQueue = Unsafe._wrap_ruby_class_as_legal(::SizedQueue)
626
697
  end
627
698
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: temporalio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Temporal Technologies Inc
@@ -66,6 +66,7 @@ files:
66
66
  - lib/temporalio/api/cloud/cloudservice.rb
67
67
  - lib/temporalio/api/cloud/cloudservice/v1/request_response.rb
68
68
  - lib/temporalio/api/cloud/cloudservice/v1/service.rb
69
+ - lib/temporalio/api/cloud/connectivityrule/v1/message.rb
69
70
  - lib/temporalio/api/cloud/identity/v1/message.rb
70
71
  - lib/temporalio/api/cloud/namespace/v1/message.rb
71
72
  - lib/temporalio/api/cloud/nexus/v1/message.rb
@@ -111,6 +112,7 @@ files:
111
112
  - lib/temporalio/api/sdk/v1/enhanced_stack_trace.rb
112
113
  - lib/temporalio/api/sdk/v1/task_complete_metadata.rb
113
114
  - lib/temporalio/api/sdk/v1/user_metadata.rb
115
+ - lib/temporalio/api/sdk/v1/worker_config.rb
114
116
  - lib/temporalio/api/sdk/v1/workflow_metadata.rb
115
117
  - lib/temporalio/api/taskqueue/v1/message.rb
116
118
  - lib/temporalio/api/testservice/v1/request_response.rb