module BuildCoordinatorStore
Constants
- AUDIT_KEY
- MAX_AUDIT_ENTRIES
- PENDING_KEY
- PLUGIN
Public Instance Methods
Source
# File lib/build_coordinator_store.rb, line 98 def append_audit(network:, channel:, event:, data:, store: RabbotDb) entries = Array( store.get_plugin_json( plugin: PLUGIN, key: AUDIT_KEY, network: network, channel: channel, default: [] ) ) entries << { "at" => store.iso_time(Time.now), "event" => event.to_s, "data" => data } store.set_plugin_json( plugin: PLUGIN, key: AUDIT_KEY, network: network, channel: channel, value: entries.last(MAX_AUDIT_ENTRIES) ) end
Source
# File lib/build_coordinator_store.rb, line 122 def audit_log(network:, channel:, store: RabbotDb) Array( store.get_plugin_json( plugin: PLUGIN, key: AUDIT_KEY, network: network, channel: channel, default: [] ) ) end
Source
# File lib/build_coordinator_store.rb, line 81 def clear_pending(network:, channel:, store: RabbotDb) store.set_plugin_json( plugin: PLUGIN, key: PENDING_KEY, network: network, channel: channel, value: {} ) end
Source
# File lib/build_coordinator_store.rb, line 38 def load_pending(network:, channel:, store: RabbotDb) payload = store.get_plugin_json( plugin: PLUGIN, key: PENDING_KEY, network: network, channel: channel ) return nil unless payload.is_a?(Hash) && !payload.empty? staged_at = store.parse_time(payload["staged_at"]) || Time.now { id: payload["id"].to_s, idea: payload["idea"].to_s, source: payload["source"].to_s, vetoed: payload["vetoed"] == true, staged_at: staged_at, veto_window_sec: payload["veto_window_sec"].to_i } end
Source
# File lib/build_coordinator_store.rb, line 58 def mark_vetoed(network:, channel:, store: RabbotDb) pending = load_pending(network: network, channel: channel, store: store) return nil unless pending pending[:vetoed] = true save_pending( network: network, channel: channel, entry: pending, staged_at: pending[:staged_at], veto_window_sec: pending[:veto_window_sec], store: store ) append_audit( network: network, channel: channel, event: "vetoed", data: { "id" => pending[:id] }, store: store ) pending end
Source
# File lib/build_coordinator_store.rb, line 134 def record_finished(network:, channel:, entry:, outcome:, store: RabbotDb) append_audit( network: network, channel: channel, event: outcome.to_s, data: { "id" => entry[:id].to_s, "idea" => entry[:idea].to_s, "source" => entry[:source].to_s }, store: store ) clear_pending(network: network, channel: channel, store: store) end
Source
# File lib/build_coordinator_store.rb, line 91 def remaining_veto_seconds(pending, now: Time.now) return 0 unless pending elapsed = now - pending[:staged_at] [pending[:veto_window_sec].to_i - elapsed.to_i, 0].max end
Source
# File lib/build_coordinator_store.rb, line 13 def save_pending(network:, channel:, entry:, staged_at:, veto_window_sec:, store: RabbotDb) payload = { "id" => entry[:id].to_s, "idea" => entry[:idea].to_s, "source" => entry[:source].to_s, "vetoed" => entry[:vetoed] == true, "staged_at" => store.iso_time(staged_at), "veto_window_sec" => veto_window_sec.to_i } store.set_plugin_json( plugin: PLUGIN, key: PENDING_KEY, network: network, channel: channel, value: payload ) append_audit( network: network, channel: channel, event: "staged", data: { "id" => payload["id"], "source" => payload["source"], "idea" => payload["idea"] }, store: store ) end