Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add redis example #36

Merged
merged 10 commits into from Jan 18, 2023
Merged

feat: add redis example #36

merged 10 commits into from Jan 18, 2023

Conversation

matthew-charles-chan
Copy link
Contributor

@matthew-charles-chan matthew-charles-chan commented Jan 12, 2023

Summary

  • Refactors plugin to improve extensibility:
    • makes @fastify/view a plugin dependency, rather than registering it within fastify-cloudprnt. This will avoid possible errors in apps which have already registered @fastify/view
    • adds routePrefix option to avoid route collisions.
    • decorates fastify with a single cloudPrnt namespace containing all the cloudprnt methods
  • Updates examples/basic to reflect the changes made to fastify-cloudprnt
  • Adds redis example (examples/redis)
  • Updates docker configuration:
    • updates Dockerfile to be used with all docker-compose files
    • adds docker compose files and associated scripts to run examples and tests
  • Updates package.json in preparation of release

Test Plan

  • clone and checkout this branch locally
  • Confirm tests pass locally
    npm run test
    
    • OR: if you have not installed cputil on your local machine, you can run containerized tests:
      npm run test:docker
  • Confirm the autotelic office printer is on and ready for connection
  • Connect your local machine to the created ngrok tunnel
    ngrok http --region=us --hostname=dev-socloudprnt.ngrok.io 3000

Redis Example

  • Start the redis example
npm run example:redis
  • Add a few print jobs to the queue using HTTPie

    http POST http://dev-socloudprnt.ngrok.io/job \
    token=testToken1 \
    jobData[token]=testToken1
    http POST http://dev-socloudprnt.ngrok.io/job \
    token=testToken2 \
    jobData[token]=testToken2
    http POST http://dev-socloudprnt.ngrok.io/job \
    token=testToken3 \
    jobData[token]=testToken3
  • Confirm the jobs have been added to the respective redis hash and list

    • sh into the running redis server
      docker exec -ti cloudprnt-redis  redis-cli
    • Confirm jobData has been created
      HGETALL printJobData
        127.0.0.1:6379> HGETALL printJobData
        1) "testToken1"
        2) "{\"token\":\"testToken1\"}"
        3) "testToken2"
        4) "{\"token\":\"testToken2\"}"
        5) "testToken3"
        6) "{\"token\":\"testToken3\"}"
    • Confirm job queue has been created
      LRANGE printJobQueue 0 -1
        127.0.0.1:6379> LRANGE printJobQueue 0 -1
        1) "testToken3"
        2) "testToken2"
        3) "testToken1"
  • The printer will poll the server within 120 seconds

  • Confirm 3 receipts are printed containing the correct tokens

  • After the receipts have been printed, confirm the jobData hash and printQueue list have been cleared

    127.0.0.1:6379> HGETALL printJobData
    (empty array)
    127.0.0.1:6379> LRANGE printJobQueue 0 -1
    (empty array)
    127.0.0.1:6379>

Note: validation status checks are currently failing. This looks to be caused by a bug in eslint-plugin-import: open issue.
Fixed in eslint-plugin-import 2.27.2

  - remove @fastify/view registration within plugin
  - wrap plugin in fastify-plugin, in order to make @fasity/view a dependency
  - decorate fastify with a single `cloudPrnt` namespace with print methods and children
  - allow a configurable prefix route
  - add docker-compose to run tests
  - add test for failing to register @fastify/view
  - add test for route prefix
@matthew-charles-chan matthew-charles-chan marked this pull request as ready for review January 12, 2023 03:07
Copy link
Member

@eadmundo eadmundo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A thing of great beauty. I provided a suggestion for the docs. LGTM!

README.md Show resolved Hide resolved
@matthew-charles-chan matthew-charles-chan merged commit 705cab1 into main Jan 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants