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

Adding a isComplete function #12 #13

Merged
merged 23 commits into from Aug 22, 2023

Conversation

ppivanov
Copy link
Contributor

@ppivanov ppivanov commented Feb 17, 2023

I have no idea how much of this works as my printer's been dead for a while, but whoever needs it can test it out and share some feedback or update the branch accordingly.

Updating print to return the job id based on what @artiebits commented on #12.
Adding isPrintComplete to query the queued jobs and will return false if it finds a row matching the job id (I'm very much assuming it should disappear when it completes).

Whoever utilizes the package can add custom polling / delays as calling isPrintComplete just once immediately after print will likely always return false.

Docs will need to be updated if you wanna go through with it

@ppivanov ppivanov changed the title Adding a isComplete function #12 Adding a isComplete function #12 (DO NOT MERGE) Feb 17, 2023
src/print/print.ts Outdated Show resolved Hide resolved
src/print/print.ts Outdated Show resolved Hide resolved
Copy link
Owner

@artiebits artiebits left a comment

Choose a reason for hiding this comment

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

Hi @ppivanov, thank you very much for the contribution. i would love to see this functionality in master, and i have just a few small comments.

src/index.ts Outdated Show resolved Hide resolved
src/print/print.ts Show resolved Hide resolved
src/utils/parse-response.ts Outdated Show resolved Hide resolved
src/utils/parse-response.ts Outdated Show resolved Hide resolved
@artiebits
Copy link
Owner

hey, I wanted to check if this work is finished. It still says "DO NOT MERGE"

@ppivanov
Copy link
Contributor Author

Hey! Still don't have the hardware to test this functionally. If anyone has gotten a chance to make sure it works I'm all for it.

@ppivanov
Copy link
Contributor Author

A new printer is on its way... Will be able to test this soon 🤞

@ppivanov ppivanov changed the title Adding a isComplete function #12 (DO NOT MERGE) Adding a isComplete function #12 Jun 12, 2023
@ppivanov
Copy link
Contributor Author

this should be fine now. would have loved someone else giving it a spin in case something obvious was missed

@ppivanov ppivanov requested a review from artiebits June 12, 2023 20:28
@artiebits
Copy link
Owner

artiebits commented Jun 13, 2023

hi @ppivanov thanks for your work! I have published a beta version unix-print@1.3.0-beta.1 to test it. let me know if it works for you, i am testing it too.

readme needs to be updated too

@shubhamgajra-memechat
Copy link

Why is a loop needed to check for print completion?

@ppivanov
Copy link
Contributor Author

ppivanov commented Aug 2, 2023

Why is a loop needed to check for print completion?

If the job is still on the queue the first time you check (e.g. immediately after it was submitted) you may want to check again after a minute or two have passed. There are probably better polling techniques that won't block the thread.

@shubhamgajra-memechat
Copy link

Any update on this @artiebits ?

@artiebits
Copy link
Owner

hi @ppivanov, sorry for such a big delay in reviewing your PR. it looks good to me, and the only comment I have is that the example in readme doesn't look valid to me because it will execute the check 10 times without any delay.
As an option, keep it consistent with other examples in the readme and do:

isPrintComplete(printJob).then(console.log)

or something like this, which will stop checking If the print job is complete in the first iteration of the loop:

async function waitForPrintCompletion(printJob) {
  while (!await isPrintComplete(printJob)) {
    // Wait a bit before checking again (to avoid constant checks)
    await new Promise(resolve => setTimeout(resolve, 1000)); // Wait for 1 second
  }
  console.log('Job complete');
}

await waitForPrintCompletion(printJob);

let's keep it simple for now!

@shubhmg
Copy link

shubhmg commented Aug 17, 2023

Can a new version be released as soon as this is merged, thanks, great work @artiebits @ppivanov! Really useful library

@artiebits
Copy link
Owner

thanks @shubhmg,

there is a beta version with this change unix-print@1.3.0-beta.1. you can already install it and check whether this functionality meets your needs.

@artiebits artiebits merged commit 3ecf2c4 into artiebits:master Aug 22, 2023
@artiebits
Copy link
Owner

@ppivanov thank you for your contribution! I will release a new version today

@artiebits artiebits mentioned this pull request Aug 22, 2023
artiebits pushed a commit that referenced this pull request Aug 22, 2023
* getJobId and isPrintComplete

* getJobId tests

* extend try-catch

* we don't ask questions here

* more tests

* undo some formatting

* deleted some stuff I shouldn't have

* tabs to spaces

* update index.ts

* messed up the exports order (:

* a few nits

* Undo changes to print fn

* remove stale non-null assertions

* format with prettier

* update tests & remove comments

* order

* fix condition

* fix tests and read stdout as expected

* Update parse-response.ts

* readme

* update readme
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

4 participants