@@ -12,20 +12,13 @@ import (
1212 "github.com/xmigrate/blxrep/utils"
1313)
1414
15- const (
16- ACTION_STATUS_STARTED = "Started"
17- ACTION_STATUS_COMPLETED = "Completed"
18- ACTION_STATUS_FAILED = "Failed"
19- ACTION_TYPE_RESTORE = "Restore"
20- ACTION_TYPE_PARTITION_RESTORE = "PartitionRestore"
21- MAX_ACTIONS_TO_PROCESS = 1000
22- )
15+ const ()
2316
2417var restorePartitionMutex sync.Mutex
2518var isPartitionRestore bool
2619
2720func StaledActions () error {
28- actions , err := service .GetAllActionsWithStatus (MAX_ACTIONS_TO_PROCESS , utils .CONST_ACTION_STATUS_IN_PROGRESS )
21+ actions , err := service .GetAllActionsWithStatus (int ( utils . CONST_MAX_ACTIONS_TO_PROCESS ) , utils .CONST_ACTION_STATUS_IN_PROGRESS )
2922 if err != nil {
3023 return fmt .Errorf ("error fetching in progress actions: %v" , err )
3124 }
@@ -86,16 +79,16 @@ func StaledActionsJob() error {
8679
8780func CheckActions (agentID string ) error {
8881 // Get pending actions
89- actions , err := service .GetAllActionsWithStatus (MAX_ACTIONS_TO_PROCESS , utils .CONST_ACTION_STATUS_WAITING )
82+ actions , err := service .GetAllActionsWithStatus (int ( utils . CONST_MAX_ACTIONS_TO_PROCESS ) , utils .CONST_ACTION_STATUS_WAITING )
9083 if err != nil {
9184 return fmt .Errorf ("error fetching pending actions: %v" , err )
9285 }
9386 utils .LogDebug (fmt .Sprintf ("Found %d pending actions for agent %s" , len (actions ), agentID ))
9487 for _ , action := range actions {
9588 // Check if the action is for this agent and is a restore action
96- if action .AgentId == agentID && action .ActionType == ACTION_TYPE_RESTORE {
89+ if action .AgentId == agentID && action .ActionType == string ( utils . CONST_AGENT_ACTION_RESTORE ) {
9790 // Update the action status to started
98- action .ActionStatus = ACTION_STATUS_STARTED
91+ action .ActionStatus = string ( utils . CONST_START_ACTION )
9992 action .TimeStarted = time .Now ().Unix ()
10093 action .ActionProgress = 1
10194
@@ -108,13 +101,13 @@ func CheckActions(agentID string) error {
108101 utils .LogDebug (fmt .Sprintf ("Starting restore action %s for agent %s" , action .Id , agentID ))
109102
110103 // Perform the restore operation
111- if action .Action == ACTION_TYPE_RESTORE {
104+ if action .Action == string ( utils . CONST_AGENT_ACTION_RESTORE ) {
112105 err := RestoreFiles (agentID , action .SourceFilePath , action .TargetFilePath , action )
113106 if err != nil {
114107 utils .LogError (fmt .Sprintf ("Error during restore for action %s: %v" , action .Id , err ))
115108
116109 // Update action status to failed
117- action .ActionStatus = ACTION_STATUS_FAILED
110+ action .ActionStatus = string ( utils . CONST_ACTION_STATUS_FAILED )
118111 action .TimeFinished = time .Now ().Unix ()
119112 err = service .InsertOrUpdateAction (action )
120113 if err != nil {
@@ -124,7 +117,7 @@ func CheckActions(agentID string) error {
124117 }
125118
126119 // Update action status to completed
127- action .ActionStatus = ACTION_STATUS_COMPLETED
120+ action .ActionStatus = string ( utils . CONST_ACTION_STATUS_COMPLETED )
128121 action .TimeFinished = time .Now ().Unix ()
129122 action .ActionProgress = 100
130123 err = service .InsertOrUpdateAction (action )
@@ -134,7 +127,7 @@ func CheckActions(agentID string) error {
134127
135128 // Log the action completion
136129 utils .LogDebug (fmt .Sprintf ("Completed restore files action %s for agent %s" , action .Id , agentID ))
137- } else if action .Action == ACTION_TYPE_PARTITION_RESTORE {
130+ } else if action .Action == string ( utils . CONST_AGENT_ACTION_PARTITION_RESTORE ) {
138131 utils .LogDebug (fmt .Sprintf ("Starting restore partition action %s for agent %s" , action .Id , agentID ))
139132 restorePartitionMutex .Lock ()
140133 var ctx context.Context
@@ -144,12 +137,12 @@ func CheckActions(agentID string) error {
144137 utils .LogError (fmt .Sprintf ("Error during restore for action %s: %v" , action .Id , err ))
145138
146139 // Update action status to failed
147- action .ActionStatus = ACTION_STATUS_FAILED
140+ action .ActionStatus = string ( utils . CONST_ACTION_STATUS_FAILED )
148141 action .TimeFinished = time .Now ().Unix ()
149142 err = service .InsertOrUpdateAction (action )
150143 }
151144 restorePartitionMutex .Unlock ()
152- action .ActionStatus = ACTION_STATUS_COMPLETED
145+ action .ActionStatus = string ( utils . CONST_ACTION_STATUS_COMPLETED )
153146 action .TimeFinished = time .Now ().Unix ()
154147 err = service .InsertOrUpdateAction (action )
155148 if err != nil {
0 commit comments