Sha256: 975b6de0a1dc2a96d113b45ece4d2ee003bfb8835665086198a0554e24e654aa

Contents?: true

Size: 1.13 KB

Versions: 97

Compression:

Stored size: 1.13 KB

Contents

module Actions
  module Middleware
    class KeepCurrentTimezone < Dynflow::Middleware
      def delay(*args)
        pass(*args).tap { store_current_timezone }
      end

      def plan(*args)
        with_current_timezone do
          pass(*args).tap { store_current_timezone }
        end
      end

      def run(*args)
        restore_curent_timezone { pass(*args) }
      end

      def finalize
        restore_curent_timezone { pass }
      end

      # Run all execution plan lifecycle hooks as the original timezone
      def hook(*args)
        restore_curent_timezone { pass(*args) }
      end

      private

      def with_current_timezone
        if action.input[:current_timezone].nil?
          yield
        else
          restore_curent_timezone { yield }
        end
      end

      def store_current_timezone
        action.input[:current_timezone] = Time.zone.name
      end

      def restore_curent_timezone
        old_zone = Time.zone
        Time.zone = Time.find_zone(action.input[:current_timezone]) if action.input[:current_timezone].present?
        yield
      ensure
        Time.zone = old_zone
      end
    end
  end
end

Version data entries

97 entries across 97 versions & 1 rubygems

Version Path
foreman-tasks-10.0.2 app/lib/actions/middleware/keep_current_timezone.rb
foreman-tasks-10.0.1 app/lib/actions/middleware/keep_current_timezone.rb
foreman-tasks-10.0.0 app/lib/actions/middleware/keep_current_timezone.rb
foreman-tasks-9.2.3 app/lib/actions/middleware/keep_current_timezone.rb
foreman-tasks-9.2.2 app/lib/actions/middleware/keep_current_timezone.rb
foreman-tasks-9.2.1 app/lib/actions/middleware/keep_current_timezone.rb
foreman-tasks-9.2.0 app/lib/actions/middleware/keep_current_timezone.rb
foreman-tasks-9.1.1 app/lib/actions/middleware/keep_current_timezone.rb
foreman-tasks-9.0.4 app/lib/actions/middleware/keep_current_timezone.rb
foreman-tasks-9.1.0 app/lib/actions/middleware/keep_current_timezone.rb
foreman-tasks-9.0.2 app/lib/actions/middleware/keep_current_timezone.rb
foreman-tasks-9.0.1 app/lib/actions/middleware/keep_current_timezone.rb
foreman-tasks-8.3.3 app/lib/actions/middleware/keep_current_timezone.rb
foreman-tasks-9.0.0 app/lib/actions/middleware/keep_current_timezone.rb
foreman-tasks-8.2.1 app/lib/actions/middleware/keep_current_timezone.rb
foreman-tasks-8.1.4 app/lib/actions/middleware/keep_current_timezone.rb
foreman-tasks-8.3.2 app/lib/actions/middleware/keep_current_timezone.rb
foreman-tasks-8.3.1 app/lib/actions/middleware/keep_current_timezone.rb
foreman-tasks-8.1.3 app/lib/actions/middleware/keep_current_timezone.rb
foreman-tasks-8.3.0 app/lib/actions/middleware/keep_current_timezone.rb