JRJurman / automated-ticket-printer

This project is an automated solution to print tickets and items as they get assigned.
MIT License
11 stars 1 forks source link

Print Queue, Start, and Watch Attributes #2

Closed JRJurman closed 8 years ago

JRJurman commented 8 years ago

Below are the details of the new features in this PR. Also included are checkboxes for things to be completed before the PR is ready to be reviewed and merged in.

Print Queue

There is now a printQueue attribute on the ActivityWatcher. This is passed into the watches getTicketObjects function, so that functions that do not immediately resolve (or take time to resolve) can add their tickets eventually. Most APIs do not immediately return values (simply put, asynchronous), so this printQueue can be interacted with when those APIs do get their values.

TLDR: Instead of returning ticket objects, put them on the printQueue.

/* old way */
getTicketObjects() {
    return [{ /* ticket object */ }]
}

/* new way */
getTicketObjects( printQueue ) {
    printQueue.unshift({ /* ticket object */ })
}

unshift is the javascript equivalent of enqueue

There is now a ActivityWatcher#start function, which starts all the watches, and creates a loop for the printers to check for new tickets in the printQueue. It has one parameter, the number of milliseconds to loop on for checking if there are new tickets.

Tickets now include a watch attribute, containing a string, that is the name of the watch they came from.
Watches include a _interval attribute, which are added by the Activity Watcher in ActivityWatcher#addWatch, so that watches can be started later, in ActivityWatcher#start.

These issues may not be addressed in this PR, but are large chunks of work, or discussion, that should be worked on in other branches.

ethanjurman commented 8 years ago

LGTM :+1:

JRJurman commented 8 years ago

@ethanjurman thanks for the review!