Commit graph

18 commits

Author SHA1 Message Date
Bradley M. Kuhn
10d809c180
Restore support for csv output format.
I took a shortcut on some previous changes and it led to only text
format being supported.  These changes bring back support for csv.
2020-09-25 10:49:34 -07:00
Bradley M. Kuhn
ee82738f0a
Header line regex was not quite right.
Note that the header line can look like this:

 --  ------ ---

… and this regex should match it.
2020-09-23 17:07:16 -07:00
Bradley M. Kuhn
bd38cf6198
More verbosity around the FIFO creation. 2020-09-23 16:46:11 -07:00
Bradley M. Kuhn
c4e5664bb5
Be exceedingly less strict on the question format.
This may ultimately be a security problem; I wanted to filter the
question for only characters that are valid in bean-query, and at
some point, the right move is to look up what characters in the
bean-query parser that are allowed.  However, I kept running into
problems of finding new characters and this was an easier hack.
2020-09-23 16:45:01 -07:00
Bradley M. Kuhn
72559aa8d6
Support Git repository and update it from upstream.
I don't remember what the --repositoryURL option was supposed to do,
but instead I now assume that the it's a Git repository if you give
--branchName and make a copy, and pull from upstream and reload when
there are updates.
2020-08-30 20:14:54 -07:00
Bradley M. Kuhn
e1857dc63f
Add getAllOutput option to query tied variable.
The separator ditching was really a hack that I made to make
unintended queries work, but generally it's relied upon by other
scripts that I use, so I've herein created an option for getting all
the output.
2020-08-30 20:12:20 -07:00
Bradley M. Kuhn
11628b4333
More verbosity when main loop starts. 2020-08-17 11:45:37 -07:00
Bradley M. Kuhn
d6914c481c
Switch from IPC::Run to Expect module; set PAGER to /usr/bin/cat
After some efforts to make this current incarnation of the daemon
work for situations with excessively long output, I discovered two
problems.

First, bean-query seems to always use a pager in interactive mode,
and it seems impossible to dissuade bean-query from this behavior
without an upstream change to Beancount.  As such, my first effort
was to force the pager to be `/usr/bin/cat`, which I thought would be
sufficient to solve the problem entirely.

After that change coupled with much debugging with IPC::Run, I found
that detecting the beancount> prompt using a regular expression of
/^\s*beancount\s*\>\s*/m, or similar efforts with simply
/\s*beancount\s*/ or other versions like /\s*beancount\s*\>\s*$/ms
/\s*beancount\s*\>\s*$/s, simply would not detect the end of the
string, so the process hung on this line in the main loop:

    pump $runningBeanQuery until $rbcOut =~ /^\s*beancount\s*\>\s*/m;

Ironically, when there is *not* copious output, that line worked just
fine.  It was baffling.

I switched to Expect, and found the exact same behavior with:

    $runningBeanQuery->expect(undef, -re => '^\s*beancount\s*\>\s*')

with that line, it works fine in the StartRunningBeanQuery()
subroutine, but when used in the main loop, Expect never finds that
string.  Again, I tried it with various regexes as specified above to
no avail.

*However*, merely changing the line to:

    $runningBeanQuery->expect(undef, 'beancount>')

(i.e., not using the regex feature in the Expect library), fixed the
problem entirely.

My working theory is some complex interaction bug between the IO::Pty
module, regular expression matching, and output timing (since this
problem only shows up when there is copious output).  I think in
particular the fact that bean-query creates a subprocess for the
`PAGER` command in the pty when the output is copious is somehow
related to the problem.

Regardless, this solution now works in all the cases where I'm using
the daemon, so I'm not investigating further.
2020-08-17 08:58:25 -07:00
Bradley M. Kuhn
381dff4cb0
Correct typo on wrong variable used; remove errant print. 2020-08-10 07:49:34 -07:00
Bradley M. Kuhn
d3395dba78
Handle repeat of query into STDOUT via pty interface to bean-query
Part of the SELECT statement that was entered gets repeated in the
output.  It's some sort of timing issue with IPC::Run or the IO::Pty
because it's often not the entire input but only part of it.

It does however appear that there is usually a blank line right
before output, and in text mode, we can also search for the line of
-'s as a backup to assure we get the proper output and don't send the
garbled input back as the output across the named pipe.

This is a bit of a hacky solution and likely error-prone.
2020-08-10 07:46:20 -07:00
Bradley M. Kuhn
9f9b110c1d
Convert to use IPC::Run in effort to make faster.
By using IPC::Run, the bean-query process need not be restarted every
time.  This shows significant speed improvement.

Note that now, the process will not notice when the Beancount files
change underneath it, or when they query format changes.  Additional
code will be needed to support this.
2020-08-10 06:37:08 -07:00
Bradley M. Kuhn
744ad08644
Allow additional characters that often appear in queries. 2020-08-09 21:02:46 -07:00
Bradley M. Kuhn
975cceeaab
Allow additional characters in bean-query queries.
These additional characters often appear in queries.

Allow them.
2020-06-15 21:29:04 -07:00
Bradley M. Kuhn
a21a35d656
Improve recovery scenario on poorly formatted queries.
Because the client defaulted to dying, this left the server in a
strange state as the query question wasn't cleared and the
“fake failure” named pipe was never opened and processed, since it
couldn't be.

The server did eventually recover when the client fully died;
however, the client has enough information to give up its query when
it knows failure has occurred, so that now happens.
2020-06-15 20:40:22 -07:00
Bradley M. Kuhn
6ef1ba0422
Support format option provided by client
The format option on bean-query command-line is now an option that
the client can pass along.  The setting defaults to whatever
`bean-query` was going to default to.
2020-06-15 20:37:49 -07:00
Bradley M. Kuhn
e9d0a8b857
Fix incorrect verbosity.
There was a logic error in the test for this verbose message.
2020-06-15 16:30:46 -07:00
Bradley M. Kuhn
8349b9610b
Only server should control fifo; client should wait for it to clear
On the a classic “concurrency is hard” front, I am slightly proud of
myself that I didn't hit this race condition but anticipated that it
might occur later.  Giving entire control to fifoName to the server
makes more sense here, and the client should not submit its query any
time either fifoName or question is set.

As an extra safeguard, the client will die if it gets the lock and
the state for submitting a query isn't right.

Finally, added some fifoName removal debugging on the server.
2020-06-15 16:29:53 -07:00
Bradley M. Kuhn
42800427f6 bean-query daemon: initial version.
This is a very basic daemon to run bean-query so that other Perl programs
can call it.  The speed savings is not really there yet, as to get that, it
would need to leave bean-query running, perhaps timing out and reloading
files as needed.  That's the long term plan.

Right now, all that this is useful for is to run another Perl process that
wants to submit and receive answers to bean-query.
2020-06-15 14:26:31 -07:00