Thanks!

I found OnProductionStop(), but I'm after something different, along the lines of calling Ens.Director.GetProductionStatus() from within OnMessage() but with a fifth possible state: ProductionStateStopping

What I'm trying to do is custom retry logic that retries on certain errors, which could mean a pretty long total hang time, so it would seem well-behaved to check every second (or so) whether it's time to shut down.

Thinking about it, it would be a lot better to be able to tell whether the host itself should stop. That is, regardless of whether it's because of a production shutdown or a stop/restart of the individual host.

...or using a stored procedure along these lines:

ClassMethod RenameTable(oldName As %String, newName As %String) As %String [ SqlProc ]
{
   try {
      &sql(select %ID into :className
         from %Dictionary.ClassDefinition
         where SqlTableName = :oldName
      )
      if SQLCODE set status = "Error: Table '" _ oldName _ "' not found." quit

      set classDef = ##class(%Dictionary.ClassDefinition).%OpenId(className)
      set classDef.SqlTableName = newName
      set saveStatus = classDef.%Save()
      set status = $case(saveStatus, 1: "OK", : "Error: " _ $system.Status.GetErrorText(saveStatus))
   } catch {
      set status = "Error: " _ $zerror
   }
   return status
}

Note: This doesn't handle the special case where there is no 'SqlTableName' defined.