Cookbook 08: A computer for every client
Five clients' books close on the same day, each on a computer of its own, so one client's records never reach another's.
By The Pine Computer team
A finance-operations firm closes September’s books for five clients on the same day. Each client’s bank statement has to be ticked off against that client’s own ledger, and the firm’s engagement says one client’s records never touch another’s.
So the program makes a computer for every client, one thread each, and in the run the five came up within a second of each other. Each computer gets its client’s statement as a file and signs in to that client’s books, and the AI ticks the statement off line by line and flags what doesn’t match. Sign-ins belong to the computer they were made on, so no client’s sign-in is ever on another’s. What comes back from each computer is the firm’s report and nothing else, and however the program ends, ensure stops all five.
# September's books for five clients, all closing today: tick each client's bank
# statement off against that client's own ledger, and report what does not match.
# Our engagement says one client's records never touch another's, and an audit has
# to see it was so -- so each client's books are done on a computer of its own.
# Nothing moves between the five: what comes home is our report, not their files.
require "pinesandbox"
require_relative "client_books"
pine = PineSandbox::Client.new(
api_key: ENV["PINE_SANDBOX_API_KEY"],
endpoint: ENV["PINE_SANDBOX_ENDPOINT"])
computers = []
begin
CLIENTS.map { |client|
Thread.new do
computer = pine.create_computer # one for every client, at once
watch(computer, computers)
session = computer.create_session(browser: true)
session.write_file("september-statement.csv", statement(client))
open_books(session)
turn = session.agent.run(goal(client), secrets: sign_in(client))
follow(session, client, turn)
save_report(session, client) # our report comes back; nothing else does
rescue => err
log(client[:slug], "ERROR #{err.class}: #{err.message}")
end
}.each(&:join)
ensure
computers.each { |c| (c.stop rescue nil) } # always, however this ends
report_table(computers.size)
endThese five computers were made for one night’s work and stopped at the end. A firm that closes every month would keep each client’s computer and start it again, still signed in, as in Cookbook 04. The five companies and their books are invented, kept on an Akaunting instance we run. More in the docs.