How to halt a integrant system












1














Context: I'm trying to set up integrant so that I can stop and start my jetty server



I'm getting:
IllegalArgumentException Don't know how to create ISeq from: clojure.lang.Var$Unbound clojure.lang.RT.seqFrom (RT.java:542)



When trying to halt my integrant system.



My Code:



(defn handler [request]
{:status 200
:headers {"Content-Type" "text/html"}
:body "Hello World!"})

(def config
{:handlers/system {:port 3000
:host "localhost"
:join? true
:http? true
:ssl? false}})

(defmethod ig/init-key :handlers/system [_ cfg]
(jetty/run-jetty handler cfg))

(defmethod ig/halt-key! :handlers/system [_ server]
(.stop server))

(defn start
(def sys (ig/init config)))

(defn stop
(ig/halt! sys))

(defn resume
(ig/resume config sys))

(defn reset
(stop)
(start))


What am I doing wrong?










share|improve this question


















  • 3




    Using def inside a function is something of a code smell; it's only rarely, if ever, appropriate. Usually, you'd be better off with a top-level (def sys (atom nil)), and then (reset sys (ig/init config)) inside your start function. (Of course, this means the other users would be @sys, not sys, to deref the atom's contents; thus, (ig/halt! @sys), and you'd probably want to reset the contents to nil when doing so).
    – Charles Duffy
    Nov 19 '18 at 14:20








  • 2




    Or use alter-var-root like github.com/weavejester/integrant-repl does (which might also be the lib you want to use instead)
    – cfrick
    Nov 19 '18 at 18:07










  • I've updated my code accordingly, thanks for the advice!
    – Clojure Pls
    Nov 20 '18 at 11:32
















1














Context: I'm trying to set up integrant so that I can stop and start my jetty server



I'm getting:
IllegalArgumentException Don't know how to create ISeq from: clojure.lang.Var$Unbound clojure.lang.RT.seqFrom (RT.java:542)



When trying to halt my integrant system.



My Code:



(defn handler [request]
{:status 200
:headers {"Content-Type" "text/html"}
:body "Hello World!"})

(def config
{:handlers/system {:port 3000
:host "localhost"
:join? true
:http? true
:ssl? false}})

(defmethod ig/init-key :handlers/system [_ cfg]
(jetty/run-jetty handler cfg))

(defmethod ig/halt-key! :handlers/system [_ server]
(.stop server))

(defn start
(def sys (ig/init config)))

(defn stop
(ig/halt! sys))

(defn resume
(ig/resume config sys))

(defn reset
(stop)
(start))


What am I doing wrong?










share|improve this question


















  • 3




    Using def inside a function is something of a code smell; it's only rarely, if ever, appropriate. Usually, you'd be better off with a top-level (def sys (atom nil)), and then (reset sys (ig/init config)) inside your start function. (Of course, this means the other users would be @sys, not sys, to deref the atom's contents; thus, (ig/halt! @sys), and you'd probably want to reset the contents to nil when doing so).
    – Charles Duffy
    Nov 19 '18 at 14:20








  • 2




    Or use alter-var-root like github.com/weavejester/integrant-repl does (which might also be the lib you want to use instead)
    – cfrick
    Nov 19 '18 at 18:07










  • I've updated my code accordingly, thanks for the advice!
    – Clojure Pls
    Nov 20 '18 at 11:32














1












1








1







Context: I'm trying to set up integrant so that I can stop and start my jetty server



I'm getting:
IllegalArgumentException Don't know how to create ISeq from: clojure.lang.Var$Unbound clojure.lang.RT.seqFrom (RT.java:542)



When trying to halt my integrant system.



My Code:



(defn handler [request]
{:status 200
:headers {"Content-Type" "text/html"}
:body "Hello World!"})

(def config
{:handlers/system {:port 3000
:host "localhost"
:join? true
:http? true
:ssl? false}})

(defmethod ig/init-key :handlers/system [_ cfg]
(jetty/run-jetty handler cfg))

(defmethod ig/halt-key! :handlers/system [_ server]
(.stop server))

(defn start
(def sys (ig/init config)))

(defn stop
(ig/halt! sys))

(defn resume
(ig/resume config sys))

(defn reset
(stop)
(start))


What am I doing wrong?










share|improve this question













Context: I'm trying to set up integrant so that I can stop and start my jetty server



I'm getting:
IllegalArgumentException Don't know how to create ISeq from: clojure.lang.Var$Unbound clojure.lang.RT.seqFrom (RT.java:542)



When trying to halt my integrant system.



My Code:



(defn handler [request]
{:status 200
:headers {"Content-Type" "text/html"}
:body "Hello World!"})

(def config
{:handlers/system {:port 3000
:host "localhost"
:join? true
:http? true
:ssl? false}})

(defmethod ig/init-key :handlers/system [_ cfg]
(jetty/run-jetty handler cfg))

(defmethod ig/halt-key! :handlers/system [_ server]
(.stop server))

(defn start
(def sys (ig/init config)))

(defn stop
(ig/halt! sys))

(defn resume
(ig/resume config sys))

(defn reset
(stop)
(start))


What am I doing wrong?







clojure






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 19 '18 at 14:16









Clojure Pls

162




162








  • 3




    Using def inside a function is something of a code smell; it's only rarely, if ever, appropriate. Usually, you'd be better off with a top-level (def sys (atom nil)), and then (reset sys (ig/init config)) inside your start function. (Of course, this means the other users would be @sys, not sys, to deref the atom's contents; thus, (ig/halt! @sys), and you'd probably want to reset the contents to nil when doing so).
    – Charles Duffy
    Nov 19 '18 at 14:20








  • 2




    Or use alter-var-root like github.com/weavejester/integrant-repl does (which might also be the lib you want to use instead)
    – cfrick
    Nov 19 '18 at 18:07










  • I've updated my code accordingly, thanks for the advice!
    – Clojure Pls
    Nov 20 '18 at 11:32














  • 3




    Using def inside a function is something of a code smell; it's only rarely, if ever, appropriate. Usually, you'd be better off with a top-level (def sys (atom nil)), and then (reset sys (ig/init config)) inside your start function. (Of course, this means the other users would be @sys, not sys, to deref the atom's contents; thus, (ig/halt! @sys), and you'd probably want to reset the contents to nil when doing so).
    – Charles Duffy
    Nov 19 '18 at 14:20








  • 2




    Or use alter-var-root like github.com/weavejester/integrant-repl does (which might also be the lib you want to use instead)
    – cfrick
    Nov 19 '18 at 18:07










  • I've updated my code accordingly, thanks for the advice!
    – Clojure Pls
    Nov 20 '18 at 11:32








3




3




Using def inside a function is something of a code smell; it's only rarely, if ever, appropriate. Usually, you'd be better off with a top-level (def sys (atom nil)), and then (reset sys (ig/init config)) inside your start function. (Of course, this means the other users would be @sys, not sys, to deref the atom's contents; thus, (ig/halt! @sys), and you'd probably want to reset the contents to nil when doing so).
– Charles Duffy
Nov 19 '18 at 14:20






Using def inside a function is something of a code smell; it's only rarely, if ever, appropriate. Usually, you'd be better off with a top-level (def sys (atom nil)), and then (reset sys (ig/init config)) inside your start function. (Of course, this means the other users would be @sys, not sys, to deref the atom's contents; thus, (ig/halt! @sys), and you'd probably want to reset the contents to nil when doing so).
– Charles Duffy
Nov 19 '18 at 14:20






2




2




Or use alter-var-root like github.com/weavejester/integrant-repl does (which might also be the lib you want to use instead)
– cfrick
Nov 19 '18 at 18:07




Or use alter-var-root like github.com/weavejester/integrant-repl does (which might also be the lib you want to use instead)
– cfrick
Nov 19 '18 at 18:07












I've updated my code accordingly, thanks for the advice!
– Clojure Pls
Nov 20 '18 at 11:32




I've updated my code accordingly, thanks for the advice!
– Clojure Pls
Nov 20 '18 at 11:32












1 Answer
1






active

oldest

votes


















1














The problem was in the config where :join? was set to true. This was blocking the process and meant that after using ctrl + c in the repl, sys hadn't been set to the return value of (ig/init config), and so when stop was called it was attempting to call .stop on an unbound fn, causing the error mentioned in the OP.






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53376532%2fhow-to-halt-a-integrant-system%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    The problem was in the config where :join? was set to true. This was blocking the process and meant that after using ctrl + c in the repl, sys hadn't been set to the return value of (ig/init config), and so when stop was called it was attempting to call .stop on an unbound fn, causing the error mentioned in the OP.






    share|improve this answer


























      1














      The problem was in the config where :join? was set to true. This was blocking the process and meant that after using ctrl + c in the repl, sys hadn't been set to the return value of (ig/init config), and so when stop was called it was attempting to call .stop on an unbound fn, causing the error mentioned in the OP.






      share|improve this answer
























        1












        1








        1






        The problem was in the config where :join? was set to true. This was blocking the process and meant that after using ctrl + c in the repl, sys hadn't been set to the return value of (ig/init config), and so when stop was called it was attempting to call .stop on an unbound fn, causing the error mentioned in the OP.






        share|improve this answer












        The problem was in the config where :join? was set to true. This was blocking the process and meant that after using ctrl + c in the repl, sys hadn't been set to the return value of (ig/init config), and so when stop was called it was attempting to call .stop on an unbound fn, causing the error mentioned in the OP.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 20 '18 at 11:36









        Clojure Pls

        162




        162






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53376532%2fhow-to-halt-a-integrant-system%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

            SQL update select statement

            WPF add header to Image with URL pettitions [duplicate]