Compare commits
3 Commits
6c32cc23cd
...
3b7138ddb7
| Author | SHA1 | Date | |
|---|---|---|---|
| 3b7138ddb7 | |||
| 661a54f665 | |||
| 5ad5e868b6 |
@@ -40,6 +40,9 @@ try {
|
||||
New-Item -ItemType Directory -Path '%s' -Force | Out-Null
|
||||
}
|
||||
|
||||
# Remove any .zip files in the destination folder before copying
|
||||
Get-ChildItem -Path "z:\" -Filter *.zip -File -ErrorAction SilentlyContinue | Remove-Item -Force -ErrorAction SilentlyContinue
|
||||
|
||||
Write-Host "Starting to copy files to the server"
|
||||
Copy-Item -Path '%s' -Destination "z:\" -Force
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ func JobScheduler(server *socketio.Server, cronTime string, jobFunc func()) {
|
||||
if err != nil {
|
||||
fmt.Printf("There was an error getting location: %v", err)
|
||||
server.BroadcastToRoom("/", "logs", "logs", fmt.Sprintf("There was an error getting location: %v", err))
|
||||
loc = time.Local
|
||||
}
|
||||
|
||||
crontJob := cron.New(cron.WithLocation(loc)) // cron.WithSeconds()
|
||||
@@ -25,7 +26,21 @@ func JobScheduler(server *socketio.Server, cronTime string, jobFunc func()) {
|
||||
// reference for the cron time format https://pkg.go.dev/github.com/robfig/cron@v1.2.0#hdr-CRON_Expression_Format
|
||||
|
||||
// we can use 6 feilds but we need to add this in with cron.WithSeconds into our cron job other wise we can use use the standard 5 fields https://crontab.guru/
|
||||
crontJob.AddFunc(cronTime, jobFunc)
|
||||
_, err = crontJob.AddFunc(cronTime, func() {
|
||||
now := time.Now().In(loc)
|
||||
msg := fmt.Sprintf("⏰ Cron job triggered at %s (spec: %s)", now.Format(time.RFC3339), cronTime)
|
||||
fmt.Println(msg)
|
||||
server.BroadcastToRoom("/", "logs", "logs", msg)
|
||||
|
||||
jobFunc()
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to add cron job (%s): %v\n", cronTime, err)
|
||||
server.BroadcastToRoom("/", "logs", "logs", fmt.Sprintf("Failed to add cron job (%s): %v\n", cronTime, err))
|
||||
return
|
||||
}
|
||||
|
||||
crontJob.Start()
|
||||
fmt.Printf("✅ Cron job scheduled: %s (TZ: %s)\n", cronTime, loc.String())
|
||||
server.BroadcastToRoom("/", "logs", "logs", fmt.Sprintf("✅ Cron job scheduled: %s (TZ: %s)\n", cronTime, loc.String()))
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ param (
|
||||
# example string to pass over, you must be in the script dir when you run this script. or it will fail to find the linked scripts
|
||||
|
||||
# If we do not pass plant to update over it will auto do all plants if we want a specific plant we need to do like below
|
||||
# .\update-controllers.ps1 -App_Path "C:\Users\matthes01\Documents\lst" -Token "test3" -BuildController no -PlantToUpdate "usmcd1vms006" -Remote_Path "E$\LST"
|
||||
# .\update-controllers.ps1 -App_Path "C:\Users\matthes01\Documents\lst" -Token "test3" -BuildController yes -PlantToUpdate "usmcd1vms036" -Remote_Path "E$\LST"
|
||||
|
||||
$Plants = @(
|
||||
@{ Server = "usmcd1vms036"; Token = "test3"; Remote_Path = "E$\LST" }
|
||||
@@ -114,7 +114,7 @@ if ($PlantToUpdate -ne "all") {
|
||||
|
||||
# Checking to make sure the server is up and online
|
||||
Write-Output "Checking if $($Token) is online to update."
|
||||
$pingResult = Test-Connection -ComputerName $Server -Count 2 -Quiet
|
||||
$pingResult = Test-Connection -ComputerName $PlantToUpdate -Count 2 -Quiet
|
||||
|
||||
if (-not $pingResult) {
|
||||
Write-Output "Server $($PlantToUpdate), token $($Token) is NOT reachable. Exiting script."
|
||||
|
||||
Reference in New Issue
Block a user