Skip to content

Commit 9340e5c

Browse files
Merge pull request #32 from figma/ck/log-heartbeat
Write to stdout every 5 minutes on master processes
2 parents 8b07033 + ae138d6 commit 9340e5c

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

javascript/src/queue/Worker.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export class Worker extends BaseRunner {
1212

1313
async *pollIter() {
1414
let lastLogTime = 0;
15+
let lastHeartbeatTime = Date.now() / 1000;
1516
await this.waitForMaster();
1617
while (
1718
!this.shutdownRequired &&
@@ -35,6 +36,12 @@ export class Worker extends BaseRunner {
3536
console.log('[ci-queue] No test to reserve, sleeping');
3637
lastLogTime = now;
3738
}
39+
40+
// Log heartbeat every 5 minutes if this is the master process
41+
if (this.isMaster && now - lastHeartbeatTime > 300) {
42+
console.log('[ci-queue] Still working');
43+
lastHeartbeatTime = now;
44+
}
3845
await sleep(500);
3946
}
4047
}

python/ciqueue/distributed.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,16 @@ def __init__(self, tests, worker_id, redis, build_id, # pylint: disable=too-man
7070

7171
def __iter__(self):
7272
def poll():
73+
last_heartbeat_time = time.time()
7374
while not self.shutdown_required and len(self): # pylint: disable=len-as-condition
7475
test = self._reserve()
7576
if test:
7677
yield test.decode()
7778
else:
79+
# Log heartbeat every 5 minutes if this is the master process
80+
if self.is_master and time.time() - last_heartbeat_time > 300:
81+
print('[ci-queue] Still working')
82+
last_heartbeat_time = time.time()
7883
time.sleep(0.05)
7984

8085
try:

ruby/lib/ci/queue/redis/worker.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,16 @@ def master?
5050

5151
def poll
5252
wait_for_master
53+
last_heartbeat_time = Time.now
5354
until shutdown_required? || config.circuit_breakers.any?(&:open?) || exhausted? || max_test_failed?
5455
if test = reserve
5556
yield index.fetch(test)
5657
else
58+
# Log heartbeat every 5 minutes if this is the master process
59+
if master? && Time.now - last_heartbeat_time > 300
60+
puts '[ci-queue] Still working'
61+
last_heartbeat_time = Time.now
62+
end
5763
sleep 0.05
5864
end
5965
end

0 commit comments

Comments
 (0)