agent/bill/monitor.go
func (m *Monitor) VerifyChannelsForInactivity() error {
	query := `
              SELECT channels.id::text
		FROM channels
                     LEFT JOIN sessions ses
                     ON channels.id = ses.channel
                     LEFT JOIN offerings offer
                     ON channels.offering = offer.id
                     INNER JOIN accounts acc
                     ON channels.agent = acc.eth_addr
               WHERE channels.service_status IN ('pending', 'active', 'suspended')
                 AND channels.channel_status NOT IN ('pending')
                 AND acc.in_use
               GROUP BY channels.id, offer.max_inactive_time_sec
              HAVING GREATEST(MAX(ses.last_usage_time), channels.service_changed_time) +
	      (offer.max_inactive_time_sec * INTERVAL '1 second') < now();`

	return m.processEachChannel(query, m.terminateService)
}
func (m *Monitor) VerifyChannelsForInactivity() error {
	query := `
              SELECT channels.id::text
		FROM channels
                     LEFT JOIN sessions ses
                     ON channels.id = ses.channel
                     LEFT JOIN offerings offer
                     ON channels.offering = offer.id
                     INNER JOIN accounts acc
                     ON channels.agent = acc.eth_addr
               WHERE channels.service_status IN ('pending', 'active', 'suspended')
                 AND channels.channel_status NOT IN ('pending')
                 AND acc.in_use
               GROUP BY channels.id, offer.max_inactive_time_sec
              HAVING GREATEST(MAX(ses.last_usage_time), channels.service_changed_time) +
	      (offer.max_inactive_time_sec * INTERVAL '1 second') < now();`

	return m.processEachChannel(query, m.terminateService)
}
// VerifyChannelsForInactivity scans all channels, that are not terminated,
// and terminates those of them, who are staying inactive too long.