Skip to content

Commit f2282a0

Browse files
authored
Merge pull request #180 from iExecBlockchainComputing/log
Add docker-compose & highlight important log messages (bad version, out of gas...)
2 parents e473af3 + f2f57b6 commit f2282a0

File tree

4 files changed

+61
-2
lines changed

4 files changed

+61
-2
lines changed

docker-compose.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
version: '3.4'
2+
3+
4+
networks:
5+
iexec-net:
6+
external: true
7+
8+
services:
9+
worker:
10+
image: nexus.iex.ec/iexec-worker:${WORKER_VERSION}
11+
container_name: worker
12+
environment:
13+
- IEXEC_CORE_HOST=core
14+
- IEXEC_CORE_PORT=18090
15+
- IEXEC_WORKER_NAME=worker
16+
- IEXEC_WORKER_WALLET_PATH=/iexec-wallets/encrypted-wallet_worker1.json
17+
- IEXEC_WORKER_RESULT_BASE_DIR=/tmp/iexec-worker
18+
ports:
19+
- 18091:18091
20+
volumes:
21+
- ./src/main/resources/wallet/encrypted-wallet_worker1.json:/iexec-wallets/encrypted-wallet_worker1.json
22+
- /tmp/iexec-worker/worker:/tmp/iexec-worker/worker
23+
- /var/run/docker.sock:/var/run/docker.sock
24+
restart: on-failure
25+
networks:
26+
- iexec-net

src/main/java/com/iexec/worker/Application.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.iexec.worker.config.WorkerConfigurationService;
1010
import com.iexec.worker.feign.CustomFeignClient;
1111
import com.iexec.worker.result.ResultService;
12+
import com.iexec.worker.utils.LoggingUtils;
1213
import com.iexec.worker.utils.version.VersionService;
1314
import lombok.extern.slf4j.Slf4j;
1415
import org.springframework.beans.factory.annotation.Autowired;
@@ -87,13 +88,17 @@ public void run(String... args) {
8788

8889
if (!publicConfiguration.getRequiredWorkerVersion().isEmpty() &&
8990
!versionService.getVersion().equals(publicConfiguration.getRequiredWorkerVersion())) {
90-
log.error("Bad version, please upgrade your iexec-worker [current:{}, required:{}]",
91+
92+
String badVersion = String.format("Bad version! please upgrade your iexec-worker [current:%s, required:%s]",
9193
versionService.getVersion(), publicConfiguration.getRequiredWorkerVersion());
94+
95+
LoggingUtils.printHighlightedMessage(badVersion);
9296
System.exit(0);
9397
}
9498

9599
if (!iexecHubService.hasEnoughGas()) {
96-
log.error("No enough gas, please refill your wallet!");
100+
String noEnoughGas = String.format("No enough gas! please refill your wallet [walletAddress:%s]", workerAddress);
101+
LoggingUtils.printHighlightedMessage(noEnoughGas);
97102
System.exit(0);
98103
}
99104

src/main/java/com/iexec/worker/executor/TaskExecutorService.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.iexec.worker.feign.CustomFeignClient;
1919
import com.iexec.worker.result.ResultService;
2020
import com.iexec.worker.sms.SmsService;
21+
import com.iexec.worker.utils.LoggingUtils;
2122

2223
import lombok.extern.slf4j.Slf4j;
2324

@@ -216,6 +217,9 @@ public void contribute(ContributionAuthorization contribAuth) {
216217

217218
if (!contributionService.hasEnoughGas()) {
218219
customFeignClient.updateReplicateStatus(chainTaskId, OUT_OF_GAS);
220+
String noEnoughGas = String.format("Out of gas! please refill your wallet [walletAddress:%s]",
221+
contribAuth.getWorkerWallet());
222+
LoggingUtils.printHighlightedMessage(noEnoughGas);
219223
System.exit(0);
220224
}
221225

@@ -250,6 +254,10 @@ public void reveal(String chainTaskId) {
250254

251255
if (!revealService.hasEnoughGas()) {
252256
customFeignClient.updateReplicateStatus(chainTaskId, OUT_OF_GAS);
257+
customFeignClient.updateReplicateStatus(chainTaskId, OUT_OF_GAS);
258+
String noEnoughGas = String.format("Out of gas! please refill your wallet [walletAddress:%s]",
259+
workerConfigurationService.getWorkerWalletAddress());
260+
LoggingUtils.printHighlightedMessage(noEnoughGas);
253261
System.exit(0);
254262
}
255263

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.iexec.worker.utils;
2+
3+
import java.util.Collections;
4+
5+
public class LoggingUtils {
6+
7+
8+
public static void printHighlightedMessage(String message) {
9+
String hashtagSequence = String.join("", Collections.nCopies(message.length() + 2, "#"));
10+
String spaceSequence = String.join("", Collections.nCopies(message.length(), " "));
11+
12+
System.out.println();
13+
System.out.println("#" + hashtagSequence + "#");
14+
System.out.println("# " + spaceSequence + " #");
15+
System.out.println("# " + message + " #");
16+
System.out.println("# " + spaceSequence + " #");
17+
System.out.println("#" + hashtagSequence + "#");
18+
System.out.println();
19+
}
20+
}

0 commit comments

Comments
 (0)