GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: My environmental monitoring stuff for the house.
Clone URL: git://github.com/dustin/environ.git
Refactored beanstalk use.
dustin (author)
Sun Jun 22 01:18:30 -0700 2008
commit  890d3ca341628bb2209e01c69a52f0f8394efc8c
tree    c87779ae8d54e1505f41fce5e27ff52d148536d7
parent  9467a2123397cf5174dbba006992ece05dca7004
...
51
52
53
54
55
 
56
57
58
59
60
61
62
63
64
65
66
67
 
 
68
69
 
 
 
 
 
 
 
 
 
 
 
70
71
72
73
74
75
76
77
78
79
80
 
 
 
 
81
82
83
...
51
52
53
 
 
54
55
56
57
 
 
 
 
 
 
 
 
 
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
 
 
 
 
 
 
 
 
 
75
76
77
78
79
80
81
0
@@ -51,33 +51,31 @@ start_handler(Owner) ->
0
       exit(Reason)
0
   end.
0
 
0
-% Send an alert via the beanstalk -> XMPP gateway
0
-gen_alert_xmpp(Subject, Msg) ->
0
+with_beanstalk(Tube, F) ->
0
   BeanstalkServer = environ_utilities:get_env(beanstalk_server, "localhost"),
0
   BeanstalkPort = environ_utilities:get_env(beanstalk_server, 11300),
0
   {ok, Socket} = beanstalk:connect(BeanstalkServer, BeanstalkPort),
0
- {using, "environ"} = beanstalk:use(
0
- environ_utilities:get_env(beanstalk_tube, "westspyxmpp"), Socket),
0
- % Flattening the list because it came from formats...
0
- Recips = environ_utilities:get_env(xmpp_notifications, []),
0
- lists:foreach(fun (To) ->
0
- {inserted, _JobID} = beanstalk:put(
0
- beanstalk_job:new(lists:flatten(
0
- To ++ " " ++ Subject ++ "\n" ++ Msg)), Socket)
0
- end, Recips),
0
+ {using, Tube} = beanstalk:use(Tube, Socket),
0
+ F(Socket),
0
   ok = gen_tcp:close(Socket).
0
 
0
+% Send an alert via the beanstalk -> XMPP gateway
0
+gen_alert_xmpp(Subject, Msg) ->
0
+ with_beanstalk("westspyxmpp", fun(Socket) ->
0
+ % Flattening the list because it came from formats...
0
+ lists:foreach(fun (To) ->
0
+ {inserted, _JobID} = beanstalk:put(
0
+ beanstalk_job:new(lists:flatten(
0
+ To ++ " " ++ Subject ++ "\n" ++ Msg)), Socket)
0
+ end, environ_utilities:get_env(xmpp_notifications, []))
0
+ end).
0
+
0
 % XXX: This will likely go away when twitter's xmpp bot is back.
0
 gen_alert_twitter(Subject, Msg) ->
0
- BeanstalkServer = environ_utilities:get_env(beanstalk_server, "localhost"),
0
- BeanstalkPort = environ_utilities:get_env(beanstalk_server, 11300),
0
- {ok, Socket} = beanstalk:connect(BeanstalkServer, BeanstalkPort),
0
- {using, "environ"} = beanstalk:use(
0
- environ_utilities:get_env(beanstalk_tube, "environ"), Socket),
0
- % Flattening the list because it came from formats...
0
- {inserted, _JobID} = beanstalk:put(
0
- beanstalk_job:new(lists:flatten(Subject ++ "\n" ++ Msg)), Socket),
0
- ok = gen_tcp:close(Socket).
0
+ with_beanstalk("environ", fun(Socket) ->
0
+ {inserted, _JobID} = beanstalk:put(
0
+ beanstalk_job:new(lists:flatten(Subject ++ "\n" ++ Msg)), Socket)
0
+ end).
0
 
0
 % Generic alert send function
0
 gen_alert(Recips, Subject, Msg) ->

Comments

    No one has commented yet.