Paste #40390: XPCore thing

Date: 2017/03/01 08:42:45 UTC-08:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


managedUpdateStatement:
    - ^inject locally requisiteDataCheck instantly
    - ^inject locally loadFile instantly
    - ^define status '<yaml[SQLManager_Offline].read[Offline_Cache.databases.%db%.status]||null>'
    - ^if <def[status].is[==].to[offline]> || <def[status].is[==].to[connecting]> {
      - announce "<&b>SQLManager<&co> <&c>Entry added to <&b>%db%<&c> offline queue!" to_console
      - yaml set Offline_Cache.databases.%db%.statements.%timestamp%:->:<def[statement]> 'id:SQLManager_Offline'
      - yaml 'savefile:SQLManager/cache.yml' 'id:SQLManager_Offline'
      }
      else {
      - if <proc[SQLManager_ConnectionCheck].context[%db%]> {
        - sql id:%db% "update:<def[statement]>" save:id
        - define id <entry[id].result.get[1].split[/].get[1]||null>
        }
        else {
        - yaml set 'id:SQLManager_Offline' 'Offline_Cache.databases.%db%.status:offline'
        - yaml set Offline_Cache.databases.%db%.statements.%timestamp%:->:<def[statement]> 'id:SQLManager_Offline'
        - yaml 'savefile:SQLManager/cache.yml' 'id:SQLManager_Offline'
        - announce "<&b>SQLManager<&co> <&c>Managed Connection Check failed for <&b>%db%<&c>!" to_console
        - announce "<&b>SQLManager<&co> <&c>Entry added to <&b>%db%<&c> offline queue!" to_console
        - run s@SQLManager p:restart def:%yamlName%|%scriptName%|%db%
        - wait 5s
        }
      }

  processOfflineQueue:
    - ^announce "<&b>SQLManager<&co> <&3>Processing Offline Queue for <&b>%db%<&3>..." to_console
    - define index '<yaml[SQLManager_Offline].list_keys[Offline_Cache.databases.%db%.statements].numerical||li@>'
    - ^if <def[index].is_empty||true> {
      - if <proc[SQLManager_ConnectionCheck].context[%db%]> {
        - yaml set 'id:SQLManager_Offline' 'Offline_Cache.databases.%db%.status:online'
        - yaml 'savefile:SQLManager/cache.yml' 'id:SQLManager_Offline'
        - announce "<&b>SQLManager<&co> <&d>%db% Now Online!" to_console
        - inject locally reloadfile instantly
        }
        else {
        - yaml set 'id:SQLManager_Offline' 'Offline_Cache.databases.%db%.status:offline'
        - announce "<&b>SQLManager<&co> <&c>Encountered an error while processing Offline queue for <&b>%db%<&c>!" to_console
        - announce "<&b>SQLManager<&co> <&c>Reverting <&b>%db%<&c> to offline mode..." to_console
        - run s@SQLManager p:restart def:%yamlName%|%scriptName%|%db%
        }
      }
      else {
      - foreach %index% {
        - define statement '<yaml[SQLManager_Offline].read[Offline_Cache.databases.%db%.statements.%value%].after[@]||null>'
        - if <proc[SQLManager_ConnectionCheck].context[%db%]> {
          - sql id:%db% "update:<def[statement]>"
          - yaml set Offline_Cache.databases.%db%.statements:<-:%value% 'id:SQLManager_Offline'
          - yaml 'savefile:SQLManager/cache.yml' 'id:SQLManager_Offline'
          - wait 1t
          }
          else {
          - yaml set 'id:SQLManager_Offline' 'Offline_Cache.databases.%db%.status:offline'
          - announce "<&b>SQLManager<&co> <&c>Encountered an error while processing Offline queue for <&b>%db%<&c>!" to_console
          - announce "<&b>SQLManager<&co> <&c>Reverting <&b>%db%<&c> to offline mode" to_console
          - run s@SQLManager p:restart def:%yamlName%|%scriptName%|%db%
          - foreach stop
          }
        }
      - if <proc[SQLManager_ConnectionCheck].context[%db%]> {
        - inject locally processOfflineQueue
        }
        else {
        - yaml set 'id:SQLManager_Offline' 'Offline_Cache.databases.%db%.status:offline'
        - announce "<&b>SQLManager<&co> <&c>Encountered an error while processing Offline queue for <&b>%db%<&c>!" to_console
        - announce "<&b>SQLManager<&co> <&c>Reverting <&b>%db%<&c> to offline mode" to_console
        - run s@SQLManager p:restart def:%yamlName%|%scriptName%|%db%
        }
      }