Webstore Health Checks testing Update Active to Websotre table

 file:///C:/Users/s.kodagoda/Downloads/Recordings/WebstoreHealthChecks.webm

https://ismegroup-my.sharepoint.com/personal/k_samaraweera_sana-commerce_com/_layouts/15/stream.aspx?id=%2Fpersonal%2Fk%5Fsamaraweera%5Fsana%2Dcommerce%5Fcom%2FDocuments%2FRecordings%2FCall%20with%20Chamath%20and%201%20other%2D20230302%5F131457%2DMeeting%20Recording%2Emp4&ga=1

The Issues are mainly 2 types,
  1. In progress scenarios
  2. Fails scenarios

Configurations are following, 

currently set as 2hrs 
Sana.Platform.Portal > DbScripts > Local



Implementation > SharedServices > HealthCheckServices



When the issue occurred 1st time,

1 In progress 
eg: When do a webstore installation, if it keeps an 'in progress' state for 2 hrs (WebjobTaskWaitingDuration)


Email Send to the Platform Team Support Inbox Group.
1. Title: Webstore health check
2 Type of fail : Upgrade in progress
3 Webstore name 
4 Webstore id 


The job will run 15/30 min rounds. 

if no one attends to it within 30 min

 then 2nd 30min Will create a ticket in Azure support dashboard

 https://sanacommerce.visualstudio.com/Sana%20Platform/_dashboards/dashboard/2e484f6f-c1e0-4af3-87fa-ee646881715e 

 it will create a record in the WebstoreHealthChecks table


1.00pm  | Email Send 1 | TicketCreated 0

1.30pm  | Email Send 1 | TicketCreated 1


Sana.Platform.Core > ConstantModels > Enums > HealthCheckType.cs

HealthCheckTypes Enum (InProgress/ Failed)

0 InProgress WebJobCheck 

1 Failed WebjobCheck

2 InProgress BackupCronJobCheck

3 Failed BackupCronJobCheck

4 InProgress HttpMonitoringConfiguration

5 Failed HttpMonitoringConfiguration


WebJobCheck: eg Installation, Activation,Restart, SSL,OpenVPN

BackupCronJobCheck: eg Backup

HttpMonitoringConfiguration: eg Http Monitoring : 


Use for Testing 

select * from WebstoreHealthChecks
select * from WebStoreStates
update WebStores set WebStoreStateId =10 where WebStoreId = 1000
update WebStores set WebStoreStateId =9, ModifiedDateTime = '2023-03-02 05:34:27.867' where WebStoreId = 1000

 update [dbo].[WebstoreHealthChecks]   set [IsTicketCreated] =0 where WebStoreId ='57055'


Table column Explain

 [Id]: unique id
,[WebStoreId]
,[HealthCheckType] : HealthCheckType enum 
,[IsEmailSent]: is the email sent or not 
,[IsTicketCreated] is the ticket
,[Description]: Email and ticked desc
,[WebstoreLifeCycleId]: Get the Last Stause of webstore
,[CheckExecutionDateTime]: after failed time which fail to check identify if (ticket Created date) 
,[FailureOccuredTime]: Issue Failed time  
,[CreatedUser]
,[CreatedDateTime]
,[ModifiedUser]
,[ModifiedDateTime]


to check the Fail scenarios update the webstore as follows  

* update WebStores set WebStoreStateId =10 (uninstall inprogress)

  where WebStoreId = 1000

  

to check inprogress/stuck senarios update webstore as folowing     

* update WebStores set WebStoreStateId =9, 

  ModifiedDateTime = '2023-03-02 05:34:27.867' (set -2hr or old) ex: now:10pm set to 8pm 

  where WebStoreId = 1000 

  

  Now job will take 2hr old data

  can change the config table [CloudConfigs] Table

  or Sana,Platform.Portal > Local > CloudConfigs.sql

SELECT * FROM [dbo].[CloudConfigs] where [key] = 'WebjobTaskWaitingDuration'


?? Better to have Ticket ID in table 



DECLARE @WebStoreStateId INT;

DECLARE @WebStoreId INT;

DECLARE @LogType INT;


DECLARE @Date DATETIME

SET @Date = GETDATE()


SET @WebStoreStateId = 26;

SET @WebStoreId = 58719

SET @LogType =5


 

--1 Update webstore as fail 

Update WebStores set WebStoreStateId =@WebStoreStateId where WebStoreId = @WebStoreId


--2 Insert life cycle  

INSERT INTO [dbo].[WebstoreLifeCycles]

           ([WebStoreId]

           ,[WebStoreStateId]

           ,[User]

           ,[Comment],[LifeCycleDate]

           )

     VALUES

           (@WebStoreId

           ,@WebStoreStateId,

           '400',

           'Failed Applied by Manualy',

            @Date)


--3. Add WebStoreLogs to attach error log


INSERT INTO [dbo].[WebStoreLogs]

           ([WebStoreId]

           ,[LogMessage]

           ,[LogType]

           ,[IsExceptionOccured]

           ,[LogDateTime])

     VALUES

           (

           @WebStoreId

           ,'<ArrayOfSanaCloudLog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

  <SanaCloudLog>

<LogMessage>Job Failed Applied by Manually</LogMessage>

  </SanaCloudLog>

</ArrayOfSanaCloudLog>

'

           ,@LogType

           ,1

           ,@Date) 



--------------------------------------------------------------------

SELECT * from WebStores where WebStoreId = 58719

SELECT * from  [dbo].[WebstoreLifeCycles] where WebStoreId = 58719

SELECT * FROM [dbo].[WebstoreHealthChecks] where WebStoreId = 58719

select * from [dbo].[WebStoreLogs] where WebStoreId = 58719



To Run web job manually

 https://portal.azure.com/#home

go tot > App services

Search webjob


Click the Webjobs

Search by browser (ctr + F)   

WebstoreHealthCheck

Click run 



---------------------------------------------------------------------------


-- UPDATE HELTHCHECK/WEBSTORE TABLES
DECLARE @WebStoreStateId INT;
DECLARE @WebStoreId INT;
DECLARE @LogType INT;
DECLARE @Date DATETIME
SET @Date = DATEADD(hour, 2, GETDATE())
DECLARE @previousDate DATETIME
SET @previousDate = DATEADD(hour, -3, GETDATE())

-- VARIABLES
SET @WebStoreStateId = 70;
SET @WebStoreId = 59038
SET @LogType =5

 
--1 UPDATE WEBSTORE AS FAIL
--Update WebStores set WebStoreStateId =@WebStoreStateId where WebStoreId = @WebStoreId

--1 UPDATE WEBSTORE AS INPROGRESS
 update WebStores set WebStoreStateId =@WebStoreStateId,
      ModifiedDateTime = @previousDate
      where WebStoreId = @WebStoreId


--2 INSERT LIFE CYCLE
INSERT INTO [dbo].[WebstoreLifeCycles]
           ([WebStoreId]
           ,[WebStoreStateId]
           ,[User]
           ,[Comment],[LifeCycleDate]
           )
     VALUES
           (@WebStoreId
           ,@WebStoreStateId,
           '400',
           'Change Manualy Applied',
            @Date)

--3.ADD WEBSTORELOGS TO ATTACH ERROR LOG
INSERT INTO [dbo].[WebStoreLogs]
           ([WebStoreId]
           ,[LogMessage]
           ,[LogType]
           ,[IsExceptionOccured]
           ,[LogDateTime])
     VALUES
           (
           @WebStoreId
           ,'<ArrayOfSanaCloudLog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <SanaCloudLog>
        <LogMessage>Job Failed Applied by Manually</LogMessage>
        </SanaCloudLog>
      </ArrayOfSanaCloudLog>
      '
           ,@LogType
           ,1
           ,@Date


--------------------------------------------------------------------

--select GETDATE()
--select DATEADD(hour, 2, GETDATE())
--select DATEADD(hour, -3, GETDATE())


-- RESET WEBSTORE TO ACTIVE
DECLARE @WebStoreStateId INT;
DECLARE @WebStoreId INT;
DECLARE @LogType INT;
DECLARE @Date DATETIME
SET @Date = DATEADD(hour, 2, GETDATE())
DECLARE @previousDate DATETIME
SET @previousDate = DATEADD(hour, -3, GETDATE())

-- VARIABLES
SET @WebStoreStateId = 2;
SET @WebStoreId = 59040
SET @LogType =5

 
--1 UPDATE WEBSTORE AS FAIL
Update WebStores set WebStoreStateId =@WebStoreStateId where WebStoreId = @WebStoreId


--2 INSERT lIFE CYCLE
INSERT INTO [dbo].[WebstoreLifeCycles]
           ([WebStoreId]
           ,[WebStoreStateId]
           ,[User]
           ,[Comment],[LifeCycleDate]
           )
     VALUES
           (@WebStoreId
           ,@WebStoreStateId,
           '400',
           'Activate Manualy Applied',
            @Date)

--update [dbo].[WebstoreLifeCycles] set [LifeCycleDate] = DATEADD(hour, 2, GETDATE())
--where [WebstoreLifeCycleId]= 160890