Skip to content

Commit 73ac675

Browse files
authored
1139 enhancement cleanup lock files (#1151)
* Added new format of lock files to .gitignore * FEAT remove lockfile when task is finished or deleted
1 parent 2efe4cf commit 73ac675

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ src/files/*
1111
*.phpproj
1212
*.sln
1313
*.phpproj.user
14-
*.lock
14+
*.lock*
1515

1616
# dynamically created by installer
1717
src/install/.htaccess

src/inc/utils/LockUtils.class.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,18 @@ public static function release($lockFile) {
4141
}
4242
}
4343
}
44+
45+
/**
46+
* Deletes a lock file associated with a specific task ID if it exists.
47+
*
48+
* @param int $taskId The unique identifier of the task associated with the lock file.
49+
*
50+
* @return void
51+
*/
52+
public static function deleteLockFile($taskId) {
53+
$lockFile = dirname(__FILE__) . "/locks/" . LOCK::CHUNKING . $taskId;
54+
if(file_exists($lockFile)) {
55+
unlink($lockFile);
56+
}
57+
}
4458
}

src/inc/utils/TaskUtils.class.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,6 +1114,7 @@ public static function deleteTask($task) {
11141114
$qF = new QueryFilter(Chunk::TASK_ID, $task->getId(), "=");
11151115
Factory::getChunkFactory()->massDeletion([Factory::FILTER => $qF]);
11161116
Factory::getTaskFactory()->delete($task);
1117+
LockUtils::deleteLockFile($task->getId());
11171118
}
11181119

11191120
/**
@@ -1188,6 +1189,7 @@ public static function checkTask($task, $agent = null) {
11881189
if ($taskWrapper->getTaskType() != DTaskTypes::SUPERTASK) {
11891190
Factory::getTaskWrapperFactory()->set($taskWrapper, TaskWrapper::PRIORITY, 0);
11901191
}
1192+
LockUtils::deleteLockFile($task->getId());
11911193
return null;
11921194
}
11931195
else if ($dispatched >= $task->getKeyspace()) {

0 commit comments

Comments
 (0)