agent/bill/monitor.go
func (m *Monitor) VerifySuspendedChannelsAndTryToUnsuspend() error {
	// All channels, that are suspended,
	// but now seems to be payed - must be unsuspended.
	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 ('suspended')
                 AND channels.channel_status NOT IN ('pending')
                 AND acc.in_use
               GROUP BY channels.id, offer.billing_interval,
                     offer.setup_price, offer.unit_price,
                     offer.max_billing_unit_lag
              HAVING COALESCE(SUM(ses.units_used), 0) /
	      offer.billing_interval - (channels.receipt_balance - offer.setup_price) /
	      offer.unit_price <= offer.max_billing_unit_lag;`

	return m.processEachChannel(query, m.unsuspendService)
}
func (m *Monitor) VerifySuspendedChannelsAndTryToUnsuspend() error {
	// All channels, that are suspended,
	// but now seems to be payed - must be unsuspended.
	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 ('suspended')
                 AND channels.channel_status NOT IN ('pending')
                 AND acc.in_use
               GROUP BY channels.id, offer.billing_interval,
                     offer.setup_price, offer.unit_price,
                     offer.max_billing_unit_lag
              HAVING COALESCE(SUM(ses.units_used), 0) /
	      offer.billing_interval - (channels.receipt_balance - offer.setup_price) /
	      offer.unit_price <= offer.max_billing_unit_lag;`

	return m.processEachChannel(query, m.unsuspendService)
}
// VerifySuspendedChannelsAndTryToUnsuspend scans all supsended channels,
// and checks if all conditions are met to unsuspend them.
// Is so - schedules task for appropriate channel unsuspending.