mirror of
https://github.com/tloncorp/landscape.git
synced 2024-12-01 10:55:45 +03:00
129 lines
3.3 KiB
Plaintext
129 lines
3.3 KiB
Plaintext
:: bark: gathers summaries from ships, sends emails to their owners
|
|
::
|
|
:: general flow is that bark gets configured with api keys and recipient
|
|
:: ships. on-demand, bark asks either all or a subset of recipients for
|
|
:: an activity summary (through the growl agent on their ships), and upon
|
|
:: receiving responses, uses the mailchimp api to upload the received
|
|
:: deets for that ship, and/or triggers an email send.
|
|
::
|
|
/- hark
|
|
/+ default-agent, verb, dbug
|
|
::
|
|
|%
|
|
+$ card card:agent:gall
|
|
+$ state-0
|
|
$: %0
|
|
api=[tlon=@t mailchimp=[key=@t list-id=@t]]
|
|
recipients=(set ship)
|
|
==
|
|
::
|
|
++ next-timer
|
|
|= now=@da
|
|
:: west-coast midnights for minimal ameri-centric disruption
|
|
%+ add ~d1.h7
|
|
(sub now (mod now ~d1))
|
|
--
|
|
::
|
|
=| state-0
|
|
=* state -
|
|
%- agent:dbug
|
|
%+ verb |
|
|
^- agent:gall
|
|
|_ =bowl:gall
|
|
+* this .
|
|
def ~(. (default-agent this %.n) bowl)
|
|
++ on-init
|
|
^- (quip card _this)
|
|
:_ this
|
|
[%pass /fetch %arvo %b %wait (next-timer now.bowl)]~
|
|
::
|
|
++ on-arvo
|
|
|= [=wire sign=sign-arvo]
|
|
^- (quip card _this)
|
|
?> =(/fetch wire)
|
|
?> ?=(%wake +<.sign)
|
|
=^ caz this (on-poke %bark-generate-summaries !>(~))
|
|
:_ this
|
|
:_ caz
|
|
[%pass /fetch %arvo %b %wait (next-timer now.bowl)]
|
|
::
|
|
++ on-poke
|
|
|= [=mark =vase]
|
|
^- (quip card _this)
|
|
?+ mark (on-poke:def mark vase)
|
|
%noun
|
|
=+ !<([m=@ n=*] vase)
|
|
$(mark m, vase (need (slew 3 vase)))
|
|
::
|
|
%set-tlon-api-key
|
|
`this(tlon.api !<(@t vase))
|
|
::
|
|
%set-mailchimp-api-key
|
|
`this(mailchimp.api !<([key=@t list=@t] vase))
|
|
::
|
|
%bark-add-recipient
|
|
=+ !<(=ship vase)
|
|
?> =(src.bowl ship)
|
|
`this(recipients (~(put in recipients) ship))
|
|
::
|
|
%bark-remove-recipient
|
|
=+ !<(=ship vase)
|
|
?> =(src.bowl ship)
|
|
`this(recipients (~(del in recipients) ship))
|
|
::
|
|
%bark-generate-summaries
|
|
?> =(src.bowl our.bowl)
|
|
:_ this
|
|
=- ~(tap in -)
|
|
^- (set card)
|
|
%- ~(run in recipients)
|
|
|= =ship
|
|
^- card
|
|
[%pass /request-summary %agent [ship %growl] %poke %growl-summarize !>(now.bowl)]
|
|
::
|
|
%bark-target-summaries
|
|
?> =(src.bowl our.bowl)
|
|
:_ this
|
|
%+ turn
|
|
(skim !<((list ship) vase) ~(has in recipients))
|
|
|= =ship
|
|
^- card
|
|
[%pass /request-summary %agent [ship %growl] %poke %growl-summarize !>(now.bowl)]
|
|
::
|
|
%bark-receive-summary
|
|
=/ result
|
|
!< %- unit
|
|
$: requested=time
|
|
$= summary
|
|
::NOTE see also /lib/summarize
|
|
$% [%life active=[s=@ud r=@ud g=@t] inactive=[d=@ud c=@ud g=@t c=@t]]
|
|
== ==
|
|
vase
|
|
?~ result
|
|
`this(recipients (~(del in recipients) src.bowl))
|
|
::TODO maybe drop the result (or re-request) if the timestamp is too old?
|
|
:_ this
|
|
:~ :* %pass /save-summary/(scot %p src.bowl)/(scot %da requested.u.result)
|
|
%arvo %k %fard
|
|
%garden %save-summary %noun
|
|
!>(`[tlon.api mailchimp.api src.bowl summary.u.result])
|
|
==
|
|
==
|
|
==
|
|
++ on-watch on-watch:def
|
|
++ on-agent on-agent:def
|
|
++ on-fail
|
|
|= [=term =tang]
|
|
(mean ':sub +on-fail' term tang)
|
|
++ on-leave
|
|
|= =path
|
|
`this
|
|
++ on-save !>(state)
|
|
++ on-load
|
|
|= old-state=vase
|
|
^- (quip card _this)
|
|
=/ old !<(state-0 old-state)
|
|
`this(state old)
|
|
++ on-peek on-peek:def
|
|
--
|