github::ActivityMonitor method fetch_new_events (protected)

 <instance of github::ActivityMonitor[i]> fetch_new_events

Defined in packages/xowiki/tcl/github-activity-monitor-procs.tcl

Fetch new events since last processed ID, at most 10 pages in single run.

Testcases:
No testcase defined.
Source code:
# Last event we processed, if any
set last_event_id [xo::dc get_value last_id {
    select max(event_id) from github_activity
}]

set events {}
set page   1
set done   0

while {!$done} {
    set body [:get "/orgs/openacs/events" [list page $page]]
    set batch [::util::json2dict $body]

    if {[llength $batch] == 0} {
        break
    }

    foreach ev $batch {
        set ev_id [dict get $ev id]

        # Events are newest-first; once we reach an older or equal ID, stop.
        if {$last_event_id ne "" && $ev_id <= $last_event_id} {
            set done 1
            break
        }

        lappend events $ev
    }

    incr page
    if {$page > 100} {
        ns_log Warning "GitHub: reached page limit while fetching events; stopping at page $page"
        break
    }
    if {$done} {
        break
    }
}

# We collected in newest-first order; reverse to oldest-first for insertion.
return [lreverse $events]
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: