11/*
2- * Copyright 2020-2023 IEXEC BLOCKCHAIN TECH
2+ * Copyright 2020-2024 IEXEC BLOCKCHAIN TECH
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
1616
1717package com .iexec .worker ;
1818
19- import com .iexec .worker . config . CoreConfigurationService ;
19+ import com .iexec .core . api . SchedulerClient ;
2020import com .iexec .worker .feign .LoginService ;
21- import com .iexec .worker .feign .client .CoreClient ;
2221import com .iexec .worker .utils .AsyncUtils ;
2322import com .iexec .worker .utils .ExecutorUtils ;
2423import com .iexec .worker .worker .WorkerService ;
@@ -38,19 +37,18 @@ public class PingService {
3837 private static final int PING_RATE_IN_SECONDS = 10 ;
3938
4039 private final Executor executor ;
41- private final CoreClient coreClient ;
42- private final CoreConfigurationService coreConfigurationService ;
40+ private final SchedulerClient schedulerClient ;
4341 private final LoginService loginService ;
4442 private final WorkerService workerService ;
4543
46- public PingService (CoreClient coreClient ,
47- CoreConfigurationService coreConfigurationService ,
44+ private String coreSessionId ;
45+
46+ public PingService (SchedulerClient schedulerClient ,
4847 LoginService loginService ,
4948 WorkerService workerService ) {
5049 executor = ExecutorUtils
5150 .newSingleThreadExecutorWithFixedSizeQueue (1 , "ping-" );
52- this .coreClient = coreClient ;
53- this .coreConfigurationService = coreConfigurationService ;
51+ this .schedulerClient = schedulerClient ;
5452 this .loginService = loginService ;
5553 this .workerService = workerService ;
5654 }
@@ -78,7 +76,7 @@ void pingScheduler() {
7876 log .debug ("Sending ping to scheduler" );
7977 final String sessionId ;
8078 try {
81- sessionId = coreClient .ping (loginService .getToken ());
79+ sessionId = schedulerClient .ping (loginService .getToken ());
8280 } catch (FeignException e ) {
8381 log .warn ("The worker cannot ping the core [status:{}]" , e .status ());
8482 if (e instanceof FeignException .Unauthorized ) {
@@ -97,16 +95,15 @@ void pingScheduler() {
9795 if (now .getMinute () == 0 && now .getSecond () <= PING_RATE_IN_SECONDS ) {
9896 log .info ("Sent ping to scheduler [sessionId:{}]" , sessionId );
9997 }
100- String currentSessionId = coreConfigurationService .getCoreSessionId ();
101- if (StringUtils .isEmpty (currentSessionId )) {
98+ if (StringUtils .isEmpty (coreSessionId )) {
10299 log .info ("First ping from the worker, setting the sessionId [coreSessionId:{}]" , sessionId );
103- coreConfigurationService . setCoreSessionId ( sessionId ) ;
100+ coreSessionId = sessionId ;
104101 return ;
105102 }
106- if (!sessionId .equalsIgnoreCase (currentSessionId )) {
103+ if (!sessionId .equalsIgnoreCase (coreSessionId )) {
107104 // need to reconnect to the core by restarting the worker
108- log .warn ("Scheduler seems to have restarted [currentSessionId:{}, " +
109- " coreSessionId:{}]" , currentSessionId , sessionId );
105+ log .warn ("Scheduler seems to have restarted [currentSessionId:{}, coreSessionId:{}]" ,
106+ coreSessionId , sessionId );
110107 workerService .restartGracefully ();
111108 }
112109 }
0 commit comments