ironmansoftware / powershell-universal

Issue tracker for PowerShell Universal
https://powershelluniversal.com
37 stars 4 forks source link

Script OneTime Schedule disappear when stop / start PSU AppPool in IIS using any version of PSU 4 #3135

Closed wsl2001 closed 8 months ago

wsl2001 commented 8 months ago

Version

4.2.12

Severity

Critical

Steps to Reproduce

Creating a onetime schedule for a script is not retaining after rebooting the machine or when recycle IIS AppPool aslo the schedule.ps1 that PSU should create in repository is not getting created. last working version of PSU checked that retain onetime schedule is PSU 3.10.2

Expected behavior

Using admin console or New-PSUSchedule should create OneTime schedule and retain it and should create schedule.ps1 file in PSU repository.

Actual behavior

Schedule disappear after rebooting the machine or recycle appppol and schedule.ps1 do not exists after creating onetime schedule even before reboot.
The schedule only exists in console and will disappear after reboot.

Cron schedule will retain and will create schedule.ps1 in repository so the issue is affecting onetime schedule only.

Additional Environment data

Windows server 2022 hosted in aws Powershell Universal version 4.2.12 hosted in IIS posted in ironman software forum as well https://forums.ironmansoftware.com/t/script-onetime-schedule-disappear-when-stop-start-psu-apppool-in-iis-using-psu-4-2-12/10371/1

Visuals

image

image

image

adamdriscoll commented 8 months ago

@wsl2001 Are you using SQL persistence?

wsl2001 commented 8 months ago

No am using liteDB

adamdriscoll commented 8 months ago

LiteDB and SQLite do not currently persist One-Time schedules during a restarted because they are using Hangfire's in-memory persistence queue. Only SQL (on soon PostgreSQL) currently persists one-time schedules across restarts.

wsl2001 commented 8 months ago

how it was working on PSU 3.10.2 with same LIteDB? Schedule.ps1 usually created with script code inside no problem and will remain there.

wsl2001 commented 8 months ago

I have installed sql express and completed the configuration of psu to use sql by updating appsettings.json file with required sql info and did migrate the data using the included migration tool and re test and still same issue using sql this time if i recycle app pool the schedule is gone.

wsl2001 commented 8 months ago

Also i need to mention if i added the schedule code in schedules.ps1 file then the schedule will retain after appPool recycle so currently only one-time schedule is broken no matter if you use admin console or script code it will not create the schedules.ps1 under repository folder and will just show the schedule in admin consle but it will disappear after appPool recycle were other options like cron it works just fine but the problem is with one-time schedule even if you dont recycle apppool at some point you have to apply windows updates which you will need to reboot the server and then any one-time schedule created will be gone. i have tried fresh installation of psu and used sql server and same results.

adamdriscoll commented 8 months ago

I see why this is happening. While the job is still scheduled in hangfire, it has been "removed" from PSU because the service was restarted. We added a check to avoid running scheduled jobs that have been removed that has caused this. We should be loading this schedule on startup to avoid this and to make sure it displays in the admin console and not just hangfire.