On 04/10/2012 06:07 AM, Alain O'Dea wrote:
> I would like to call mod_zotonic_status_vcs:event/2 from a Webmachine
> resource.
>
> I'm essentially trying to trigger a {vcs_up, [{site, SiteName}]}
> postback when Github sends me a POST as part of their Post-Receive Hooks.
>
> My initial thought is to construct a #postback{} record and call the
> event/2 directly, but that seems like an underhanded hack especially
> since I can't think of valid values for trigger and target :)
Since #postback{} is a record, you dont need to fill in values for
trigger and target. That's why the postback has been converted to a
record in the first place :)
I guess the correct way to do this is to use z_notifier...
z_notifier:notify(#postback{message={vcs_up, [{site, SiteName}]}}, Context)
would do the trick.
It's not a real "postback" of course, since there is no browser<->server
interaction, but I guess in your case that's not the point anyway.
Arjan
How does z_notifier:notify/2 know to call mod_zotonic_status_vcs:event/2?
There are no calls to z_notifier:observe/3 or z_notifier:observe/4 in mod_zotonic_status_vcs, I see that (z_module_manager.erl, line 716) searches through the exported functions and collects all functions beginning with observe_ and pid_observe_ and adds them as observers. That only explains possible calls to mod_zotonic_status_vcs:observe_zotonic_status_init/3 when notifications occur with a zotonic_static_init event.
Would I be correct to assume that z_notifier:notify/2 will not work in my case based on this?
As always, pull requests welcome :-D
Arjan
On 04/11/2012 09:10 AM, Marc Worrell wrote:
>
> On 11 apr 2012, at 03:42, Alain O'Dea wrote:
>
>> How does *z_notifier:notify/2* know to call
>> *mod_zotonic_status_vcs:event/2*?
>
> Actually, it doesn't.
> It will call observe_postback/2 (if present when the module was loaded).
>
>> There are no calls to *z_notifier:observe/3* or *z_notifier:observe/4*
>> in *mod_zotonic_status_vcs*, I see that (z_module_manager.erl, line
>> 716)
>> <https://github.com/zotonic/zotonic/blob/master/src/support/z_module_manager.erl#L716>
>> searches through the exported functions and collects all functions
>> beginning with observe_ and pid_observe_ and adds them as observers.
>> That only explains possible calls to
>> *mod_zotonic_status_vcs:observe_zotonic_status_init/3* when
>> notifications occur with a *zotonic_static_init event*.
>>
>> Would I be correct to assume that *z_notifier:notify/2* will not work