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-5.3.0 app/lib/actions/middleware/keep_current_timezone.rb
foreman-tasks-5.2.0 app/lib/actions/middleware/keep_current_timezone.rb
foreman-tasks-5.1.1 app/lib/actions/middleware/keep_current_timezone.rb
foreman-tasks-5.1.0 app/lib/actions/middleware/keep_current_timezone.rb
foreman-tasks-4.1.5 app/lib/actions/middleware/keep_current_timezone.rb
foreman-tasks-4.1.4 app/lib/actions/middleware/keep_current_timezone.rb
foreman-tasks-4.1.3 app/lib/actions/middleware/keep_current_timezone.rb
foreman-tasks-3.0.6 app/lib/actions/middleware/keep_current_timezone.rb
foreman-tasks-5.0.0 app/lib/actions/middleware/keep_current_timezone.rb
foreman-tasks-4.1.2 app/lib/actions/middleware/keep_current_timezone.rb
foreman-tasks-4.1.1 app/lib/actions/middleware/keep_current_timezone.rb
foreman-tasks-4.0.1 app/lib/actions/middleware/keep_current_timezone.rb
foreman-tasks-4.1.0 app/lib/actions/middleware/keep_current_timezone.rb
foreman-tasks-3.0.5 app/lib/actions/middleware/keep_current_timezone.rb
foreman-tasks-4.0.0 app/lib/actions/middleware/keep_current_timezone.rb
foreman-tasks-3.0.4 app/lib/actions/middleware/keep_current_timezone.rb
foreman-tasks-2.0.3 app/lib/actions/middleware/keep_current_timezone.rb
foreman-tasks-3.0.3 app/lib/actions/middleware/keep_current_timezone.rb
foreman-tasks-3.0.2 app/lib/actions/middleware/keep_current_timezone.rb
foreman-tasks-3.0.1 app/lib/actions/middleware/keep_current_timezone.rb