From 698f4a8f6999d3faee87ae6321274b58d7ae13e8 Mon Sep 17 00:00:00 2001 From: valrus Date: Wed, 8 Sep 2021 21:54:13 -0700 Subject: [PATCH] Add process_type to service DSL This enables mpd to be run with the "Interactive" value, which avoids performance issues such as skipping when playing music. See this PR, where this was done previously: https://github.com/Homebrew/homebrew-core/pull/19410 The ProcessType plist key was lost in the conversion to the service DSL: https://github.com/Homebrew/homebrew-core/commit/483ad1fdfa29f10441b5de4386173e68f4b11555 --- Library/Homebrew/service.rb | 22 ++++++++++++++++++++++ Library/Homebrew/test/service_spec.rb | 4 ++++ 2 files changed, 26 insertions(+) diff --git a/Library/Homebrew/service.rb b/Library/Homebrew/service.rb index 3165d9ea9b..493dcfb42e 100644 --- a/Library/Homebrew/service.rb +++ b/Library/Homebrew/service.rb @@ -13,6 +13,11 @@ module Homebrew RUN_TYPE_INTERVAL = "interval" RUN_TYPE_CRON = "cron" + PROCESS_TYPE_BACKGROUND = "background" + PROCESS_TYPE_STANDARD = "standard" + PROCESS_TYPE_INTERACTIVE = "interactive" + PROCESS_TYPE_ADAPTIVE = "adaptive" + # sig { params(formula: Formula).void } def initialize(formula, &block) @formula = formula @@ -119,6 +124,22 @@ module Homebrew end end + sig { params(type: T.nilable(String)).returns(T.nilable(String)) } + def process_type(type = nil) + case T.unsafe(type) + when nil + @process_type + when PROCESS_TYPE_BACKGROUND, PROCESS_TYPE_STANDARD, PROCESS_TYPE_INTERACTIVE, PROCESS_TYPE_ADAPTIVE + @process_type = type.to_s + when String + raise TypeError, "Service#process_type allows: "\ + "'#{PROCESS_TYPE_BACKGROUND}'/'#{PROCESS_TYPE_STANDARD}'/"\ + "'#{PROCESS_TYPE_INTERACTIVE}'/'#{PROCESS_TYPE_ADAPTIVE}'" + else + raise TypeError, "Service#process_type expects a String" + end + end + sig { params(type: T.nilable(T.any(String, Symbol))).returns(T.nilable(String)) } def run_type(type = nil) case T.unsafe(type) @@ -193,6 +214,7 @@ module Homebrew base[:KeepAlive] = @keep_alive if @keep_alive == true base[:LegacyTimers] = @macos_legacy_timers if @macos_legacy_timers == true base[:TimeOut] = @restart_delay if @restart_delay.present? + base[:ProcessType] = @process_type.capitalize if @process_type.present? base[:WorkingDirectory] = @working_dir if @working_dir.present? base[:RootDirectory] = @root_dir if @root_dir.present? base[:StandardInPath] = @input_path if @input_path.present? diff --git a/Library/Homebrew/test/service_spec.rb b/Library/Homebrew/test/service_spec.rb index efa4391798..4c63811914 100644 --- a/Library/Homebrew/test/service_spec.rb +++ b/Library/Homebrew/test/service_spec.rb @@ -76,6 +76,7 @@ describe Homebrew::Service do root_dir var working_dir var keep_alive true + process_type "interactive" restart_delay 30 macos_legacy_timers true end @@ -101,6 +102,8 @@ describe Homebrew::Service do \thomebrew.mxcl.formula_name \tLegacyTimers \t + \tProcessType + \tInteractive \tProgramArguments \t \t\t#{HOMEBREW_PREFIX}/opt/formula_name/bin/beanstalkd @@ -165,6 +168,7 @@ describe Homebrew::Service do root_dir var working_dir var keep_alive true + process_type "interactive" restart_delay 30 macos_legacy_timers true end