Skip to content

Commit

Permalink
removed cancelation of mob timers
Browse files Browse the repository at this point in the history
  • Loading branch information
hollesse committed Jan 25, 2024
1 parent fdc41ce commit b262d34
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 145 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 4.4.7
- Removes feature which cancels running timers as this can lead to longer rotations if the codebase is switched. The way it was implemented is also not ideal for virus detection.

# 4.4.6

- Fix: Able to open last modified file with space in path
Expand Down
92 changes: 1 addition & 91 deletions mob.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
)

const (
versionNumber = "4.4.6"
versionNumber = "4.4.7"
minimumGitVersion = "2.13.0"
)

Expand Down Expand Up @@ -534,7 +534,6 @@ func startTimer(timerInMinutes string, configuration config.Configuration) {
}

if startLocalTimer {
abortRunningTimers()
err := executeCommandsInBackgroundProcess(getSleepCommand(timeoutInSeconds), getVoiceCommand(configuration.VoiceMessage, configuration.VoiceCommand), getNotifyCommand(configuration.NotifyMessage, configuration.NotifyCommand), "echo \"mobTimer\"")

if err != nil {
Expand All @@ -547,92 +546,6 @@ func startTimer(timerInMinutes string, configuration config.Configuration) {
say.Info("It's now " + currentTime() + ". " + fmt.Sprintf("%d min timer ends at approx. %s", timeoutInMinutes, timeOfTimeout) + ". Happy collaborating! :)")
}

func abortRunningTimers() {
processIds := findMobTimerProcessIds()
for _, processId := range processIds {
killRunningProcess(processId)
}
}

func killRunningProcess(processId string) {
var err error
switch runtime.GOOS {
case "darwin", "linux":
err = killRunningProcessLinuxAndDarwin(processId)
break
case "windows":
err = killRunningProcessWindows(processId)
}
if err != nil {
say.Error(fmt.Sprintf("old timer couldn't be aborted on your system (%s)", runtime.GOOS))
say.Error(err.Error())
}
say.Debug("Killed mob timer with PID " + processId)
}

func killRunningProcessLinuxAndDarwin(processId string) error {
_, _, err := runCommandSilent("kill", processId)
return err
}

func killRunningProcessWindows(processId string) error {
_, _, err := runCommandSilent("powershell", "-command", "Stop-Process", "-Id", processId)
return err
}

func findMobTimerProcessIds() []string {
say.Debug("find all mob timer processes")
switch runtime.GOOS {
case "darwin", "linux":
return findMobTimerProcessIdsLinuxAndDarwin()
case "windows":
return findMobTimerProcessIdsWindows()
}
return []string{}
}

func findMobTimerProcessIdsWindows() []string {
_, output, err := runCommandSilent("powershell", "-command", "Get-WmiObject", "Win32_Process", "-Filter", "\"commandLine LIKE '%mobTimer%'\"", "|", "Select-Object", "-Property", "ProcessId,CommandLine", "|", "Out-String", "-Width", "10000")
if err != nil {
say.Error(fmt.Sprintf("could not find processes on your system (%s)", runtime.GOOS))
say.Error(err.Error())
}
lines := strings.Split(output, "\r\n")
var filteredLines []string
for _, line := range lines {
if line != "" {
filteredLines = append(filteredLines, line)
}
}
processInfos := filteredLines[2:]
var timerProcessIds []string
for _, processInfo := range processInfos {
if strings.Contains(processInfo, "echo \"mobTimer\"") {
timerProcessIds = append(timerProcessIds, strings.Split(strings.TrimSpace(processInfo), " ")[0])
}
}
return timerProcessIds
}

func findMobTimerProcessIdsLinuxAndDarwin() []string {
_, output, err := runCommandSilent("ps", "-axo", "pid,command")
lines := strings.Split(output, "\n")
if err != nil {
say.Error(fmt.Sprintf("could not find processes on your system (%s)", runtime.GOOS))
say.Error(err.Error())
}
var processIds []string
for _, line := range lines {
if strings.Contains(line, "echo \"mobTimer\"") {
line = strings.TrimSpace(line)
processId := strings.Split(line, " ")[0]
processIds = append(processIds, processId)
say.Debug("Found mob timer with PID " + processId)
}
}
return processIds
}

func getMobTimerRoom(configuration config.Configuration) string {
if !isGit() {
say.Debug("timer not in git repository, using MOB_TIMER_ROOM for room name")
Expand Down Expand Up @@ -686,7 +599,6 @@ func startBreakTimer(timerInMinutes string, configuration config.Configuration)
}

if startLocalTimer {
abortRunningTimers()
err := executeCommandsInBackgroundProcess(getSleepCommand(timeoutInSeconds), getVoiceCommand("mob start", configuration.VoiceCommand), getNotifyCommand("mob start", configuration.NotifyCommand), "echo \"mobTimer\"")

if err != nil {
Expand Down Expand Up @@ -1096,7 +1008,6 @@ func next(configuration config.Configuration) {
gitWithoutEmptyStrings("push", gitHooksOption(configuration), configuration.RemoteName, currentWipBranch.Name)
}
showNext(configuration)
abortRunningTimers()

if !configuration.NextStay {
git("checkout", currentBaseBranch.Name)
Expand Down Expand Up @@ -1261,7 +1172,6 @@ func done(configuration config.Configuration) {
git("branch", "-D", wipBranch.Name)
say.Info("someone else already ended your session")
}
abortRunningTimers()
}

func gitDir() string {
Expand Down
54 changes: 0 additions & 54 deletions mob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
config "github.com/remotemobprogramming/mob/v4/configuration"
"github.com/remotemobprogramming/mob/v4/open"
"github.com/remotemobprogramming/mob/v4/say"
"github.com/remotemobprogramming/mob/v4/test"
"os"
"path/filepath"
"reflect"
Expand Down Expand Up @@ -1724,58 +1723,6 @@ func TestHelpRequested(t *testing.T) {
equals(t, true, helpRequested([]string{"s", "10", "-h"}))
}

func TestAbortTimerIfNewTimerIsStarted(t *testing.T) {
_, configuration := setup(t)
startTimer("10", configuration)
assertSingleTimerProcess(t)

startTimer("10", configuration)

assertSingleTimerProcess(t)
abortRunningTimers()
}

func assertSingleTimerProcess(t *testing.T) {
test.Await(t, func() bool { return 1 == len(findMobTimerProcessIds()) }, "exactly 1 mob timer process found")
}

func assertNoTimerProcess(t *testing.T) {
test.Await(t, func() bool { return 0 == len(findMobTimerProcessIds()) }, "no mob timer process found")
}

func TestAbortBreakTimerIfNewBreakTimerIsStarted(t *testing.T) {
_, configuration := setup(t)
startBreakTimer("10", configuration)
assertSingleTimerProcess(t)

startBreakTimer("10", configuration)

assertSingleTimerProcess(t)
abortRunningTimers()
}

func TestAbortTimerIfMobNext(t *testing.T) {
_, configuration := setup(t)
start(configuration)
startTimer("10", configuration)
assertSingleTimerProcess(t)

next(configuration)

assertNoTimerProcess(t)
}

func TestAbortTimerIfMobDone(t *testing.T) {
_, configuration := setup(t)
start(configuration)
startTimer("10", configuration)
assertSingleTimerProcess(t)

done(configuration)

assertNoTimerProcess(t)
}

func TestOpenTimerInBrowserWithTimerRoom(t *testing.T) {
mockOpenInBrowser()
output, configuration := setup(t)
Expand Down Expand Up @@ -1931,7 +1878,6 @@ func setup(t *testing.T) (output *string, configuration config.Configuration) {
equals(t, []string{"master"}, gitBranches())
equals(t, []string{"origin/master"}, gitRemoteBranches())
assertNoMobSessionBranches(t, configuration, "mob-session")
abortRunningTimers()
output = captureOutput(t)
return output, configuration
}
Expand Down

0 comments on commit b262d34

Please sign in to comment.