You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2018/09/25 17:05:48 UTC

[GitHub] sijie closed pull request #2635: Gracefully shutdown function worker service

sijie closed pull request #2635: Gracefully shutdown function worker service
URL: https://github.com/apache/pulsar/pull/2635
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/FunctionWorkerStarter.java b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/FunctionWorkerStarter.java
index 2a3dc0f445..ab5332bd33 100644
--- a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/FunctionWorkerStarter.java
+++ b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/FunctionWorkerStarter.java
@@ -23,9 +23,12 @@
 import com.beust.jcommander.JCommander;
 import com.beust.jcommander.Parameter;
 
+import lombok.extern.slf4j.Slf4j;
+
 /**
  * A starter to start function worker.
  */
+@Slf4j
 public class FunctionWorkerStarter {
 
     private static class WorkerArguments {
@@ -60,6 +63,16 @@ public static void main(String[] args) throws Exception {
         }
 
         final Worker worker = new Worker(workerConfig);
-        worker.startAsync();
+        try {
+            worker.start();
+        }catch(Exception e){
+            log.error("Failed to start function worker", e);
+            worker.stop();
+            System.exit(-1);
+        }
+        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
+            log.info("Stopping function worker service ..");
+            worker.stop();
+        }));
     }
 }
diff --git a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/Worker.java b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/Worker.java
index cb73eaa16f..9163defe3b 100644
--- a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/Worker.java
+++ b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/Worker.java
@@ -34,7 +34,7 @@
 import java.util.HashSet;
 
 @Slf4j
-public class Worker extends AbstractService {
+public class Worker {
 
     private final WorkerConfig workerConfig;
     private final WorkerService workerService;
@@ -45,19 +45,7 @@ public Worker(WorkerConfig workerConfig) {
         this.workerService = new WorkerService(workerConfig);
     }
 
-    @Override
-    protected void doStart() {
-        try {
-            doStartImpl();
-        } catch (InterruptedException ie) {
-            Thread.currentThread().interrupt();
-            log.error("Interrupted at starting worker", ie);
-        } catch (Throwable t) {
-            log.error("Failed to start worker", t);
-        }
-    }
-
-    protected void doStartImpl() throws Exception {
+    protected void start() throws Exception {
         URI dlogUri = initialize(this.workerConfig);
 
         workerService.start(dlogUri);
@@ -146,11 +134,15 @@ private static URI initialize(WorkerConfig workerConfig)
         }
     }
 
-    @Override
-    protected void doStop() {
-        if (null != this.server) {
-            this.server.stop();
+    protected void stop() {
+        try {
+            if (null != this.server) {
+                this.server.stop();
+            }
+            workerService.stop();    
+        }catch(Exception e) {
+            log.warn("Failed to gracefully stop worker service ", e);
         }
-        workerService.stop();
+        
     }
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services