1
0
Fork 0
Commit Graph

140 Commits (master)

Author SHA1 Message Date
Austin Schaffer 3c5cffc34f [DEV-6721] Pass canterm to individual raters 2020-01-31 14:15:22 -05:00
Shelly Shaver 8967583349 [DEV-6325] Return previous rating results on rate call 2020-01-24 09:08:47 -05:00
Austin Schaffer 61b66c24a3 [DEV-6730] Store concluding_save with the reverse delta 2020-01-15 10:26:07 -05:00
Schaffer, Austin aea913e767 [DEV-5314] Do not publish directly to postrate exchange after rating 2020-01-02 16:42:25 -05:00
Austin Schaffer 1cb47d4acf [DEV-6710] [WIP] Save environment on quote save 2019-12-19 14:17:06 -05:00
Austin Schaffer 542745da8a [DEV-5312] Log quote_id along with doc_id 2019-12-17 11:59:06 -05:00
Austin Schaffer e3dded760d [DEV-5312] Define document meta data and restructure message writer.
Add better tests for message writer
2019-12-12 10:27:09 -05:00
Austin Schaffer d9ee999adb [DEV-5312] Refactor class dependencies
Move create config functions out of the main delta-processor.ts file. Change some any types to more specific types. Define document structure better. Move prometheus logic out of processor class. Do not call logger directly, listen for events and log them. Change logger to more PSR-3 compliant style. Extract amqp connection into its own class. Create avro and mongo objects in factory.
2019-12-12 10:14:54 -05:00
Austin Schaffer e737850efd [DEV-5312] Set processed flag 2019-11-12 17:10:19 -05:00
Austin Schaffer c5733d1dff [DEV-5312] Add interface for amqp publisher and implement a delta publisher 2019-11-12 17:04:54 -05:00
Burzlaff, Herbert 341aeb6a08 [DEVOPS-143] Node 12, needs a callback for asynchronous file writes, so switching to synchronous file writes instead 2019-11-12 16:21:01 -05:00
Austin Schaffer 950ae8818b [DEV-5312] Add preliminary processor 2019-11-12 16:21:01 -05:00
Austin Schaffer 91a7cf94b2 [DEV-5312] Add dao for deltas 2019-11-12 16:21:01 -05:00
Austin Schaffer bdd77f8de4 [DEV-5312] Workaround multiple easejs instances 2019-11-11 15:15:28 -05:00
Austin Schaffer 015a3f5d47 [DEV-5312] Convert MongoServerDao to TS 2019-11-11 15:14:49 -05:00
Austin Schaffer c2458dee78 [DEV-5312] Convert most parts of RatingService Publish to TS 2019-11-11 09:29:07 -05:00
Mike Gerwitz 1e5a0fb701 events: Use EventEmitter from old version of Node
This was copied from a _very_ early version of node.  The problem is that,
for reasons not yet investigated, Node v12's EventEmitter (at least when
extended by easejs) is causing data to be shared across instances.

This kicks the can down the road a little bit.  The goal is to eventually
get rid of EventEmitter entirely.

Here's the script used to do the conversion in this commit:

git grep -l "require( 'events' )" -- src \
  | while read f; do
      path=$( sed 's|src/||;s|[^/]\+|..|g' <<< "$(dirname "$f")" )
      sed -i "s|require( 'events' )|require( '$path/events' )|" "$f"
    done
2019-11-08 13:06:18 -05:00
Austin Schaffer cda048dd8c [DEV-6353] Generate and save reverse deltas for ratingdata and step save 2019-11-07 16:25:33 -05:00
Austin Schaffer 26c4367ead [DEV-6353] Accept push data in MongoDao 2019-11-07 16:25:33 -05:00
Austin Schaffer 48aa315c2a [DEV-6353] Get and set past rate data 2019-11-07 16:25:33 -05:00
Austin Schaffer 9f8fb90d0d [DEV-6353] Add dapi definitions 2019-11-07 16:25:33 -05:00
Austin Schaffer 4f39c754a2 [DEV-6353] Add bucket definitions 2019-11-07 16:25:33 -05:00
Austin Schaffer 6fcf72f1b6 [DEV-6353] Convert DataProcessor to TS 2019-11-07 16:25:33 -05:00
Mike Gerwitz 64718d5513 RatingService: Fix initialRatedDate and lastRatedDate reply
Recent changes caused the quote to be read before it was mutated by
_saveRatingData.
2019-10-31 14:26:12 -04:00
Mike Gerwitz f0e246deef RatingService#postProcessRaterData: Fix accidental indvRate change
I accidentally changed id=>after when prototyping data for the _new_
deferred rating (not yet written).  There were no tests for this code, which
was originally written in July of 2012 (see private lovullo.git repo), so it
was not caught until QA.
2019-10-31 11:21:01 -04:00
Mike Gerwitz cefd6e95cb RatingService: Remove unnecessary program param
It was kept for postProcessRaterData for now since that would involve
modifying a subtype as well.
2019-10-29 13:36:55 -04:00
Mike Gerwitz 65e7880c81 RatingService: Improved error handling
This does only a slightly better job than before.
2019-10-29 13:36:55 -04:00
Mike Gerwitz a23f2040dd RatingService: Remove unreachable error check 2019-10-29 13:36:55 -04:00
Mike Gerwitz 1ed8ad1cd7 RatingService: Return promise
This only replaces the callbacks at the highest level and starts to move
toward proper error handling.  The private methods do not yet properly
propagate errors.
2019-10-29 13:36:55 -04:00
Mike Gerwitz 1aa69c2a56 RatingService: Save rating data to separate field (ratedata)
This adds ratedata to the quote collection.  We use the existing saveQuote
method so that this operation is atomic.  We're also continuing to save to
the bucket for now so as not to break existing code, but the intent in the
future will be to remove all but necessary data that should be exposed to
the client.
2019-10-29 13:36:55 -04:00
Mike Gerwitz 312142b3e8 RatingService: Use ServerDao
I had forgotten an interface exists, and this will be needed for the next
commit.  Unfortunately it requires a bit of duplication with
MongoServerDao.d.ts, for now.
2019-10-29 13:36:55 -04:00
Mike Gerwitz 767a248e44 RatingService: Convert to TypeScript
This was an adventure, and was also used as a peer programming exercise to
introduce TypeScript to other programmers in the office.

This class has far too many dependencies, which made this difficult.  The
approach was to create .d.ts files for dependencies and wait on moving those
over for now, otherwise the task will never get done.

The RatingServicePublic trait was left as such for the time being; I was
able to work around a bug that was making it difficult to mix it into a
prototype.

There were no logic changes; this was just type refactoring.
2019-10-29 13:36:41 -04:00
Mike Gerwitz 5552de93d5 Rater: Remove interface
It's used only by HttpRater and the interface is no longer adhered to by
DslRater (which no longer implements it).
2019-10-24 10:30:14 -04:00
Mike Gerwitz 7583cc1a71 RatingServiceSubmitNotify: Remove unused trait 2019-10-21 14:06:47 -04:00
Mike Gerwitz 16409a014f TokenedDataApi: Accept or kill token
Rather than leaving a token in a DONE state, we should either transition to
ACCEPTED or DEAD depending on whether the token was superceded.

* src/server/dapi/TokenedDataApi.ts (_replyUnlessStale): Accept token when
  not superceded, otherwise kill.
  [store]: New param.
  (request): Use it.
* test/server/dapi/TokenedDataApiTest.ts: Update accordingly.
2019-10-18 09:55:11 -04:00
Mike Gerwitz e003abcd4b Integrate TokenedDataApi into system
This changes the easejs interface for DataApi, which requires adding the
param to everything.  The TS interface was created in a previous commit and
already contained this parameter.  The idea is to remove the easejs
interface in the future, but traits are a barrier to that atm.

DocumentServer and controller demonstrate the mess that we have with regards
to instantiating dependencies.  This needs to change---DocumentServer itself
was something that was started but never fully realized.  It makes this
incredibly confusing, difficult to follow, and complicates important error
handling that ought to be taking place.  It also discourages implementing
additional dependencies.

I'm not going to go through and provide a ChangeLog-style commit message for
this commit.  I'm too exhausted by this crap.
2019-10-18 09:55:11 -04:00
Mike Gerwitz d8c065817f NodeCallback<T, R>: New type to simplify callback declarations
Just trying to reduce some boilerplate.  I kept this as a separate commit to
illustrate clearly how this type of things is done since we'll have people
learning TypeScript.

* src/types/misc.ts (NodeCallback<T,R>): New type.
* src/server/dapi/TokenedDataApi.ts: Use it.
* test/server/dapi/TokenedDataApiTest.ts: Use it.
2019-10-18 09:55:11 -04:00
Mike Gerwitz 07c8b55475 TokenedDataApi: New class
This integrates the PersistentTokenStore into the DataAPI system via a
decorator.  Unfortunately, it requires an API change and propagating data
through the system is a huge mess, which is the topic of a following
commit.  The API modification was a compromise.

This modifies the interface of DataApi to include a third parameter.  I am
continuing to export the old easejs interface for an incremental migration
away from it.  That old interface will be modified next commit, since
it requires modifying a lot of files and will muddy up this commit.

* src/dapi/DataApi.ts: Rename from js.  Add types.  Add new interface.
  Continue exporting old.
* src/server/dapi/TokenedDataApi.ts: New class.
* test/server/dapi/TokenedDataApiTest.ts: New test cases.
2019-10-18 09:55:11 -04:00
Mike Gerwitz b3ab082e9c {=>Persistent}TokenStore
This creates an interface for TokenStore.  The main motivation of this right
now is testing, since I'm punting on figuring out a mock framework right
now (due to time constraints).

* src/server/token/TokenStore.ts: Rename file.
* src/server/token/store/PersistentTokenStore.ts: Rename from TokenStore.
* test/server/token/TokenStoreTest.ts: Rename file.
* test/server/token/store/PersistentTokenStoreTest.ts: Rename from TokenStoreTest.
2019-10-18 09:55:11 -04:00
Mike Gerwitz d1f72cf5b3 MongoTokenDao, TokenStore: Simplify constructors
This is a feature that I originally wished I could introduce into easejs.  I
enjoyed it in Scala.  Cuts down on a lot of boilerplate.

* src/server/token/MongoTokenDao.ts (constructor): Remove fields and replace
  with inline definitions.
* src/server/token/TokenStore.ts (constructor): Likewise.
2019-10-18 09:55:10 -04:00
Mike Gerwitz c8589a1c57 TokenDao, TokenStore: Track most recently created tokens
This is much more useful information than the last modified.  For example:

- Token A is created.  It becomes the last modified.
- Token B is created.  It becomes the last modified.
- Token A completes.  Mismatch.  It becomes the last modified.
- Token B completes.  Mismatch.  It becomes the last modified.

So in this case, we're unable to use the flag to determine whether we should
ignore the token.  But if we instead us the new flag to see what token was
last _created_, the problem is solved.

This should have been obvious the first time around.

* src/server/token/MongoTokenDao.ts (updateToken): Query
    `lastState'.  Return its value.  Update its value.
  (getToken): Query lastState.  Return its value.
* src/server/token/Token.ts (Token)[last_state]: New field.
* src/server/token/TokenDao.ts (TokenQueryResult, TokenNamespaceResults):
    Use type instead of interface.
  (TokenStateHistory): New type.
  (TokenNamespaceData)[lastState]: New optional field.
  (TokenData)[prev_state]: New field.
* src/server/token/TokenStore.ts: Return previous state data for each
    method.
* test/server/token/MongoTokenDaoTest.ts: Add last_state.
* test/server/token/TokenStoreTest.ts: Likewise.
2019-10-18 09:55:10 -04:00
Mike Gerwitz 0a9a5fe56e TokenStore: Provide document id via constructor
The primary use case for this is currently the DataAPI, and the quote id is
only available at the highest level of the server, before dapis are
processed.

In any case, the TokenStore was already described in terms of a combination
of document id; namespace; and root field; so it makes sense for doc id to
be part of the constructor.

If a more generic TokenStore is needed in the future, we could go back to
the previous API and wrap it in another class, like a partially applied
function (e.g. `DocumentTokenStore`).

* src/server/token/TokenStore.ts: Move doc_id out of arguments and into the
  constructor.
* test/server/token/TokenStoreTest.ts: Update accordingly.
2019-10-18 09:55:10 -04:00
Mike Gerwitz 929acf0e90 TokenStore: Implement for token lookups and creation
Does not yet support token updates.

* src/server/token/Token.ts (TokenStateDeadable, TokenStateDoneable,
  TokenStateAcceptable, Token): New types.
* src/server/token/TokenStore.ts: New class.
* test/server/token/TokenStoreTest.ts: New test case.
2019-10-18 09:55:10 -04:00
Mike Gerwitz 9997da3f65 TokenDao: Return previous state
This causes the DAO to return the state of the document prior to the
database operation (in the case of a retrieval, the previous state is the
same as the current state).  This will allow determining whether other
tokens were modified since a previous request.

* src/server/token/MongoTokenDao.ts: Stop using TokenType in favor of new
    TokenState.
  (updateToken): Query for and return previous state.  Use findAndModify
    instead of update.
  (getToken): Return previous state.  Minor changes to account for new
    TokenQueryResult types (null=>undefined).
* src/server/token/Token.ts: Add comments for existing Token{Id,Namespace}
    nominal types.
  (TokenState): New string enum.
* src/server/token/TokenDao.ts: Import new TokenState.
  (TokenDao)[updateToken]: Use it.
  (TokenType): Remove.
  (TokenQueryResult, TokenNamespaceResults, TokenNamespaceData):
    null=>undefined for unavailable value.  null was wrong.
  (TokenStatus): Token{Type=>State}.
  (TokenData)[prev_state, prev_status]: New fields.
* test/server/token/MongoTokenDaoTest.ts: Update tests accordingly.
2019-10-18 09:55:10 -04:00
Mike Gerwitz 5b279f77cb TokenDao (#updateToken): Return updated data
Since some of these data are generated within TokenDao (e.g. the timestamp),
the caller cannot infer all values.

* src/server/token/MongoTokenDao.ts (updateToken): Return
  Promise<{void=>TokenData}>.
* src/server/token/TokenDao.ts (TokenDao)[#updateToken]: Update interface
  accordingly.
* test/server/token/MongoTokenDaoTest.ts: Update test accordingly.
2019-10-18 09:55:10 -04:00
Mike Gerwitz 4454e40e19 TokenDao: Add error context 2019-10-18 09:55:10 -04:00
Mike Gerwitz 1f66a25658 TokenDao: Better error handling for unknown tokens
Rather than replying with null, which complicates using the returned promise
efficiently, we'll respond with a unique error that allows us to distinguish
between a database failure and a missing token.

These are more traditional errors, but we're moving toward structured
logging, so I want error objects that provide more context.  I'll explore
that a bit more in next commit.  Unfortunately, the untypedness of Promise
rejections make for a less than desirable situation here.  Async/await is
not yet an option since we're still compiling to ES5 (have to support
IE11), and TS compiles async/await into generators for environments that
don't support them, which also are not available in ES5.

* src/server/service/TokenedService.js (_getQuoteToken): Remove null check,
  since this situation can no longer occur.
* src/server/token/MongoTokenDao.ts (getToken): Remove null from return type
  union; reject with `UnknownTokenError' instead.
* src/server/token/TokenDao.ts: Modify interface accordingly.
* src/server/token/UnknownTokenError.ts: New class.
* test/server/token/MongoTokenDaoTest.ts: Modify tests accordingly.  Add
  missing test for latest token namespace missing.
2019-10-17 11:47:14 -04:00
Mike Gerwitz fb88ceeae6 TokenDao: class=>interface
TokenDao has been renamed to MongoTokenDao.  While it's good for this to
have its own interface anyway, the immediate motivation was for unit tests:
I started playing with mocking with TypeScript and researching some
libraries, but I don't have time to research enough to commit to any of them
at the moment.  Interfaces remove the need to mock at all.

This also stops using `export default' in favor of just importing by
name.  Using defaults only saves us a few characters, and it makes for
awkward syntax in various cases (e.g. with multiple exports).  But I'm still
new to TS, so who knows if I'll be flip-flopping on this decision in the
future.  If we kept to our normal 1:1 file:definition convention, it
wouldn't cause problems, but based on the types I've had to define so far,
that'd cause way too much bloat and boilerplate.

* src/server/daemon/controller.js: No long import `default'.  Use
  `MongoTokenDao'.
* src/server/token/TokenedService.js: Stop checking type (since TS
  interfaces do not result in compiler output, easejs cannot validate
  against them.)
* src/server/token/MongoTokenDao.ts: Rename from `TokenDao.ts'.
* src/server/token/TokenDao.ts: Rename from `TokenQueryResult.ts'.
  (TokenDao): New interface.
* src/server/token/TokenQueryResult.ts: Rename to `TokenDao.ts'.
* test/server/token/MongoTokenDaoTest.ts: Rename from `TokenDaoTest.ts'.
2019-10-17 11:47:14 -04:00
Mike Gerwitz 37f1b86ac1 TokenDao: "quote"=>"document" with nominal type
* src/document/Document.ts: New file.
* src/server/token/TokenDao.ts: quote=>document and use DocumentId.
* test/server/token/TokenDaoTest.ts: Likewise.
2019-10-17 11:47:14 -04:00
Mike Gerwitz 54b3f0db72 TokenDao: Nominal typing
This beings an experiment with nominal typing using what the TS community
calls "branding".  The lack of nominal types was one of my biggest
disappointments with TS, so this should really help to mitigate bugs
resulting from misappropriation of data.

* src/server/token/Token.ts: New file.
* src/server/token/TokenDao.ts: Use Token{Id,Namespace}.
* src/server/token/TokenQueryResult.ts: Likewise.
* src/types/misc.d.ts: Introduce NominalType and UnixTimestamp.
* test/server/token/TokenDaoTest.ts: Use nominal types.
2019-10-17 11:47:14 -04:00