11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/textus/infra/refresh/detached.rb', line 11
def spawn(store_root:, key:)
return nil unless supported?
pid = Process.fork do
$stdin.close
$stdout.reopen(File::NULL, "w")
$stderr.reopen(File::NULL, "w")
lock = Textus::Infra::Refresh::Lock.new(root: store_root, key: key)
exit(0) unless lock.try_acquire
begin
store = Textus::Store.new(store_root)
Textus::Refresh.call(store, key, as: "script")
rescue StandardError
ensure
lock.release
exit(0)
end
end
Process.detach(pid)
pid
end
|