kmahon37 / plex-dvr-waker

Plex DVR Waker is a simple command-line tool for waking the computer before the next scheduled recording.
MIT License
8 stars 0 forks source link

[BUG] Windows Task Scheduler 0x80008091 error code #13

Closed mdrob closed 4 years ago

mdrob commented 4 years ago

Hello Kris – I’m keen to implement this tool that you have created, however I don’t seem to be able to get it working. Would appreciate your assistance, thank you.

Describe the bug Windows Task Scheduler reports that last run result for both DVR sync and monitor as 0x80008091.

To Reproduce dotnet PlexDvrWaker.dll add-task --sync and dotnet PlexDvrWaker.dll add-task --monitor have been tried which result in the same error code.

Expected behavior I understood that both the sync and monitor tasks could be used and would subsequently update the wakeup task.

Desktop (please complete the following information):

Additional context If I run dotnet PlexDvrWaker.dll add-task –wakeup, the command appears to be properly scheduled to run when the next programme is due to record - have attached the log file if this helps. One other thing that caught my attention was the fact that the dotnet PlexDvrWaker.dll list [--maintenance] command doesn't seem to be 'printing' the scheduled maintenance that my Plex server has set up? Again, any assistance with that would also be very well received.

PlexDvrWaker.log

mdrob commented 4 years ago

Seems to be going down hill, the .NET Core Host now keeps stopping responding...

image

image

kmahon37 commented 4 years ago

I think I see the (potential) problem in the code. I'll need to test it and fix it (give me a day or so). Also, when running commands from the command line, you should remove the square brackets (ie: [ ]) - they are only meant to indicate optional parameters. So in your screenshot above you would actually want to run the command line as dotnet PlexDvrWaker.dll list --maintenance

mdrob commented 4 years ago

Thanks Kris - yes my oversight regarding the square brackets, I was trying to save time by copying and pasting into Command Prompt! Reran without them and looks like it's still crashing. Appreciate your prompt response and look forward to hearing back from you again.

kmahon37 commented 4 years ago

Fixed in v1.1.5 Give this version a try and let me know if it works for you.

mdrob commented 4 years ago

Hi Kris - removed the old version, installed the new and reran. Looks like it's still crashing when running dotnet PlexDvrWaker.dll add-task --sync and dotnet PlexDvrWaker.dll add-task --monitor.

appcrash.txt

kmahon37 commented 4 years ago

Do you have a screenshot/stacktrace of the command line error when you run dotnet PlexDvrWaker.dll add-task --sync and dotnet PlexDvrWaker.dll add-task --monitor? That would be the most helpful.

Do the dotnet PlexDvrWaker.dll add-task --wakeup and dotnet PlexDvrWaker.dll list commands work correctly?

I see that you are on Win7, and that may have something to do with it (just guessing based on the code that executes for add-task --sync and add-task --monitor). The library I use to interact with the Windows Task Scheduler claims to work back to WinXP, but it may need PowerShell installed for some things (as of right now, I'm not 100% sure about this). I currently run Win10, so I may need to spin up test Win7 Pro SP1 instance in order to better test this.

mdrob commented 4 years ago

Screenshots as below, thanks:

image

image

PlexDvrWaker.dll add-task --wakeup does not work, however dotnet PlexDvrWaker.dll list does seem to be okay.

kmahon37 commented 4 years ago

Oops, looks like I accidentally introduced a bug in v1.1.5 that broke the add-task command when the task didn't exist yet. Sorry about that. I fixed it in v1.1.6. Can you give v1.1.6 a try and send me a screenshot of the command line errors again for the following?

mdrob commented 4 years ago

No worries, okay so both v1.1.6 dotnet PlexDvrWaker.dll add-task --sync and dotnet PlexDvrWaker.dll add-task --monitor now work again. It's just the original issue of Windows Task Scheduler reporting the last run result for these as 0x80008091.

kmahon37 commented 4 years ago

Fixed in 1.1.7 (hopefully)

I was able to duplicate your "last run result" error on a Win7 machine. The problem seems to be that the Win7 Task Scheduler cannot find the dotnet.exe. I came up with a solution to launch the tasks using syntax like cmd.exe /k start dotnet.exe ... and this seems to allow it to have access to the PATH environment variable and find dotnet.exe for both Win7 and Win10.

Let me know if v1.1.7 works for you or not.

mdrob commented 4 years ago

I've tried 1.1.7 and it looks like this is heading in the right direction, however it's not completely working as intended.

First, I tried the monitor task and it didn't create the wake-up task, then when I added the wake-up task manually it didn't appear to be update automatically with Plex changes (only showed the next recording or maintenance event when first run by myself).

I thought it would be best to begin basic troubleshooting with the sync task. As above when run, it didn't create the wake-up task and when I added that manually it picked up the next recording or maintenance event as above e.g. wouldn't update with changes in Plex. Task Scheduler was reporting 0x41301 run results against the sync task - some research led me to change the setting under 'if the task is already running' to 'stop the existing instance'.

With the above setting tweaked, this seems to be working okay now and the wake-up task is being updated accordingly. Screenshot below from Task Scheduler - I'm assuming that the ongoing run results are 'okay'? I have adjusted the sync interval to 5 minutes to minimise the risk of the wake-up task not being updated when scheduling recording in Plex.

image

kmahon37 commented 4 years ago

OK, I think I got it this time. Give v1.1.8 a try. Since you installed and tried v1.1.7, make sure to pay attention to the "upgrade notes".

My approach in v1.1.7 was flawed, as you discovered, and causes multiple unseen issues. Running cmd.exe /k ... causes Task Scheduler to continue running the task indefinitely, which appeared to work for the monitor task, but not the others. In v1.1.8, I've gone back to a simpler approach of just trying to locate the dotnet.exe either in it's default install location of %ProgramFiles%\dotnet\dotnet.exe or in a location defined in the PATH environment variable. I then use the full path location of dotnet.exe in the created tasks in Task Scheduler.

JWohlgem commented 4 years ago

I tried a clean install of this tool on Windows 10 1903 and tried the latest release and the scheduled tasks fail to launch dotnet.exe, despite it being installed in the default location and being in the system path.

JWohlgem commented 4 years ago

I tried 1.1.8 from the link above, and it avoids the failure to find dotnet.exe when launching the scheduled task, but the task quickly exits with error code 0xE0434352.

kmahon37 commented 4 years ago

@JWohlgem Thanks for the information, I'm seeing the same thing now too on my Win10, although I swear it was working for me the other day.

kmahon37 commented 4 years ago

@JWohlgem I think I found the problem with v1.1.8, and a possible solution. I want to do some more testing this weekend before pushing out a new release.

kmahon37 commented 4 years ago

I think I have everything working again. 🤞 Please give the pre-release v1.1.9 a try. Please let me know if v1.1.9 works for both of you or not. If everything is successful then I'll make v1.1.9 the latest release. Thanks

@mdrob I've tested v1.1.9 on both Win7 and Win10, and everything seems to be working in regards to finding the dotnet.exe when running the task from Windows Task Scheduler.

@JWohlgem I've tested v1.1.9 and verified that the scheduled tasks no longer exit with the error code 0xE0434352 caused by a bug in v1.1.8. The scheduled tasks have been running correctly for me this weekend.

JWohlgem commented 4 years ago

@kmahon37 Thanks! I installed v1.1.9 and confirmed the DVR monitor task doesn't error out anymore. Further, I see that DVR sync executed successfully once. This is my first time using your project, so I'll let you know if I see anything else as I gain experience with it.

mdrob commented 4 years ago

Hey Kris - apologies for the delay in getting back, I've not had chance to update the v1.1.7 that I have installed right now. I'll take a look at the latest version you've been working on and get back to you.

kmahon37 commented 4 years ago

Closing this because I believe it was fixed with v1.1.9. Also, I just released v2.0.0 that supports .NET Core 3.1 which makes these problems go away because I no longer need to find the location of the dotnet.exe.

mdrob commented 4 years ago

Hello Kris - I've tried the latest version v2.0.0 without much success. The monitor command leaves Task Scheduler sat with a last run result of 0x8004131F and I wasn't able to get the sync interval argument working from command prompt. Given that I couldn't get monitoring to work, I manually altered sync in the Task Scheduler to repeat every minute.

kmahon37 commented 4 years ago

@mdrob That error code seems to indicate that an instance of Plex DVR Waker is already running for that task. I did test v2.0.0 on a Win7 machine and everything seemed to work for me.

When you installed v2.0.0, did you follow the upgrade instructions in the readme (also copied/edit below for you)? Specifically, since you installed the broken v1.1.7 and v1.1.8, it is important that after deleting v1.1.7 and v1.1.8 that you also reboot your machine. Normally a reboot wouldn't be required, but in this case v1.1.7 and v1.1.8 incorrectly kept the program running in the background and only a reboot will kill it.

(the below is copied from the readme, and step 2 is edited for you in italics)

Upgrades

If you are upgrading from a previous version of Plex DVR Waker, please follow these steps.

  1. If you are using the monitor task, then you must first stop it before you can delete/overwrite the PlexDvrWaker.exe file.
    1. Open the Windows Task Scheduler.
    2. Go to the "Plex DVR Waker" folder.
    3. Right-click on the "DVR monitor" task, and click "End".
  2. Delete the folder containing your previous version of Plex DVR Waker.
    • If you previously had v.1.1.7 or v1.1.8, then reboot your machine before installing the new version in the next step.
  3. Unzip the contents of the new version.
  4. If you are upgrading to a newer major version (ie: 1.x.x -> 2.x.x), then you may need to open an "Administrator" Command Prompt and rerun the add-task commands that you are using. Doing this will update the existing tasks in Windows Task Scheduler with any potential breaking changes for the new Plex DVR Waker version.