mheily / jobd

A job management framework
Other
143 stars 15 forks source link

Prevent duplicate jobs from running, resolves mheily/relaunchd#9 #21

Closed sgerbino closed 8 years ago

sgerbino commented 8 years ago

This patch shoud resolve issue #9.

The code change produces the following output:

[sgerbino@elysium relaunchd]$ ./launchd 
[sgerbino@elysium relaunchd]$ sh launchctl load test/fixtures/sleepy.json 
[sgerbino@elysium relaunchd]$ sh launchctl load test/fixtures/sleepy.json 
[sgerbino@elysium relaunchd]$ sh launchctl load test/fixtures/sleepy.json 
[sgerbino@elysium relaunchd]$ sh launchctl load test/fixtures/sleepy.json 
[sgerbino@elysium relaunchd]$ sh launchctl load test/fixtures/sleepy.json 
[sgerbino@elysium relaunchd]$ sh launchctl list
PID      Status   Label
29394    0        sleepy
[sgerbino@elysium relaunchd]$ cat ~/.launchd/launchd.log 
update_jobs(manager.c:172): WARNING: job sleepy is already running
update_jobs(manager.c:172): WARNING: job sleepy is already running
update_jobs(manager.c:172): WARNING: job sleepy is already running
update_jobs(manager.c:172): WARNING: job sleepy is already running
mheily commented 8 years ago

I created a utility function for looking up jobs by label, and committed it in 3283b77. Let's refactor this patch to use the utility function.

sgerbino commented 8 years ago

The first loop should prevent jobs from running that are already running. The second loop is to prevent loading the same job twice if 2 of the same job are in the pending LIST.