module P4PhoenixServices class ChangeCommitHandler # Sinatra settings attr_accessor :settings # Handle to web_api attr_accessor :web_api_client # Handle to phoenix_updater attr_accessor :phoenix_updater_client def initialize(settings: nil, web_api_client: nil, phoenix_updater_client: nil) @settings = settings @web_api_client = web_api_client @phoenix_updater_client = phoenix_updater_client end # Use the changeroot variable and try to guess what projects might have # been affected by the commit. If any have been, then trigger an update # message to the phoenix_updater. # # Right now, we only really submit checks in two cases: # # 1. The changeroot is a substring of any project compare_path # 2. The changeroot is a parent string (minus the /...) of any project's # compare_path for include or include+ path types only. # # For projects that match these cases, we just check each project's latest # change, then issue an update only if we update the change number. def run(values) return if !values.key?('changeroot') changeroot = values['changeroot'] search_path = changeroot.gsub(/^(.*)\/.../, $1) projects = Projects.dataset .select_all(:projects) .join(:streams, :project_iid, :projects__iid) .join(:paths, :stream_iid, :streams__iid) .from(:projects) .where('strpos(?, paths.changeroot) = 0', search_path) .or("(strpos(paths.changeroot, ?) = 0 AND (paths.path_type = 'include' or paths.path_type == 'include+'))", search_path) .all projects.each { |p| check_project_change(p) } end # Make a query to grab the latest change number on the stream. If the # stream has a *later* change, we trigger an update. def check_project_change(project) changes = web_api_client.changes(max:1, files: "#{project.stream.stream}/...") unless changes.empty? change = changes.first if change.change.to_i > project.change project.change = change.change.to_i project.save phoenix_updater_client.update(project: project.id, change: project.change) end end end end end
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 13972 | tjuricek |
Removing old microservice implementations. The system is now mostly a monolith. Eventually there will be a websocket service. |
||
#1 | 13472 | tjuricek |
Implementation of the phoenix services side of notification handling. This is just implementation and work-in-progress. Phoenix projects will now have paths cached in the phoenix services process, which we'll use to "guess" what file changes affect which Phoenix project. We basically see a changed path, then see that it might be relevant to one of the Phoenix project stream views, and then issue a "p4 changes -m1 //stream..." to see what the last change number is. If the change number goes up, we trigger an update. Note that how this all gets configured is with an account from notification services to phoenix services, which ideally is some kind of system account that sees all relevant files. Otherwise, you'll likely get changes filtered by protections, and thus, updates may not get sent out. |