Oh, I found my mistake. I was calling the function instead of giving it to 
.start Thread. This was wrong:


(defn process-startup-hooks-that-run-in-their-own-threads []
  "2013-02-21- remember, each row in hooks is a map: {:order-of-events 2 
:event-name 'delete-old-sessions'} "
  (let [hooks (sort-by :order-of-events 
(:events-called-when-the-app-starts-that-run-in-their-own-threads-hooks 
@um/interactions))]
    (doseq [x hooks]
      (let [event-as-string (:event-name x)
            event-as-symbol (symbol event-as-string)
            event (ns-resolve @event-namespace event-as-symbol)]
        (if-not (nil? event)
          (.start (Thread. (event))))))))

and I guess this is right:


(defn process-startup-hooks-that-run-in-their-own-threads []
  "2013-02-21- remember, each row in hooks is a map: {:order-of-events 2 
:event-name 'delete-old-sessions'} "
  (let [hooks (sort-by :order-of-events 
(:events-called-when-the-app-starts-that-run-in-their-own-threads-hooks 
@um/interactions))]
    (doseq [x hooks]
      (let [event-as-string (:event-name x)
            event-as-symbol (symbol event-as-string)
            event (ns-resolve @event-namespace event-as-symbol)]
        (if-not (nil? event)
          (.start (Thread. event)))))))



On Tuesday, March 5, 2013 4:11:53 PM UTC-5, larry google groups wrote:
>
> Huh, interesting. So, I had this set of maps that had the names of the 
> functions that I wanted to be started in their own threads once the app 
> started up, but apparently only the first one gets called:
>
>
>    :events-called-when-the-app-starts-that-run-in-their-own-threads-hooks 
> #{
>                                                                           
>   {:order-of-events 1 :event-name "omniture-fetch-new-data"}
>                                                                           
>   {:order-of-events 2 :event-name "persist-new-log-data-to-database"}
>                                                                           
>   {:order-of-events 3 :event-name 
> "omniture-call-api-for-report-if-status-is-ready"}                         
>                   
>                                                                           
>   }
>
>
> omniture-fetch-new-data fires up, but the other 2 functions do not. Does 
> the one sort of hijack everything else? 
>
>
> On Tuesday, March 5, 2013 3:24:14 PM UTC-5, larry google groups wrote:
>>
>>
>> This surprises me. I thought I could start my app, then start some 
>> functions in separate threads, and then call Jetty to connect my app 
>> to a socket and have it serve requests. But the way I did this did not 
>> work. I had first had this: 
>>
>> (defn -main [& args] 
>>   (let [port (Integer/parseInt (first args)) 
>>         level-of-debugging (str (second args))] 
>>     (try 
>>       (set-the-current-debugging-level level-of-debugging) 
>>       (um/update-interactions) 
>>       (pe/set-event-namespace core-namespace) 
>>       (pe/process-startup-hooks) 
>>       (pe/process-startup-hooks-that-run-in-their-own-threads) 
>>       (run-jetty #'app {:port (or port 8080) :join? false}) 
>>       (catch Exception e (debug/print-error-info e))))) 
>>
>> In this case, run-jetty never got called. The function that starts up 
>> the other functions in their own threads is: 
>>
>>
>> (defn process-startup-hooks-that-run-in-their-own-threads [] 
>>   "2013-02-21- remember, each row in hooks is a map: {:order-of-events 
>> 2 :event-name 'delete-old-sessions'} " 
>>   (let [hooks (sort-by :order-of-events (:events-called-when-the-app- 
>> starts-that-run-in-their-own-threads-hooks @um/interactions))] 
>>     (doseq [x hooks] 
>>       (let [event-as-string (:event-name x) 
>>             event-as-symbol (symbol event-as-string) 
>>             event (ns-resolve @event-namespace event-as-symbol)] 
>>         (if-not (nil? event) 
>>           (.start (Thread. (event)))))))) 
>>
>> This seems to somehow hijack the main thread, so that run-jetty never 
>> gets called. 
>>
>> If I do this instead, then everything is fine: 
>>
>>
>> (defn -main [& args] 
>>   (let [port (Integer/parseInt (first args)) 
>>         level-of-debugging (str (second args))] 
>>     (try 
>>       (set-the-current-debugging-level level-of-debugging) 
>>       (um/update-interactions) 
>>       (pe/set-event-namespace core-namespace) 
>>       (pe/process-startup-hooks) 
>>       (run-jetty #'app {:port (or port 8080) :join? false}) 
>>       (pe/process-startup-hooks-that-run-in-their-own-threads) 
>>       (catch Exception e (debug/print-error-info e))))) 
>>
>>
>> run-jetty is called, and then the other functions startup . 
>>
>> But why did my first version of -main not work the way I expected? 
>>
>>

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to