Skip to content

Commit

Permalink
cleanup: docs and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
prmichaelsen committed Nov 27, 2018
1 parent d8ed09c commit f4473e8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/firebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ admin.initializeApp({
databaseURL: config.firebase.databaseUrl,
});

export const firebase = admin;
export const db = admin.database();
export const firebase = admin;
4 changes: 4 additions & 0 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import { Job } from '@prmichaelsen/hb-common';
import { RobinhoodWebApi } from 'robinhood';
import { isNullOrUndefined } from 'util';

/**
* retrieve the user's robinhood token for this job and
* authenticate a robinhood api client
*/
export const rh = (job: Job.Job): Promise<RobinhoodWebApi> => new Promise((resolve, reject) => {
firebase.database().ref(['robinhood-tokens', job.userId].join('/'))
.once('value', snapshot => {
Expand Down
3 changes: 3 additions & 0 deletions src/jobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
} from 'util';
import _ = require('lodash');

/** the code to execute when the job is running */
export const run = async (job: DeepImmutableObject<Job.Job>): Promise<Job.Job> => {
switch (job.type) {
case Job.Type.MarketCalendar: {
Expand Down Expand Up @@ -289,6 +290,7 @@ export const run = async (job: DeepImmutableObject<Job.Job>): Promise<Job.Job> =
}
};

/** a chance to reject jobs because of a bad request */
export const validate = async (job: DeepImmutableObject<Job.Job>): Promise<Job.Job> => {
const data = { ...job };
switch (job.type) {
Expand Down Expand Up @@ -348,6 +350,7 @@ export const validate = async (job: DeepImmutableObject<Job.Job>): Promise<Job.J
}
};

/** poll a 3rd party service for more information before continuing the job */
export const pend = async (job: DeepImmutableObject<Job.Job>): Promise<Job.Job> => {
switch (job.type) {
case Job.Type.Daytrade: {
Expand Down

0 comments on commit f4473e8

Please sign in to comment.