Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit f379b05

Browse files
author
Michael Grauer
committed
ENH: refs #68. Added work_dir to Task model.
1 parent ff8b49d commit f379b05

File tree

6 files changed

+38
-24
lines changed

6 files changed

+38
-24
lines changed

modules/batchmake/controllers/components/KWBatchmakeComponent.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -453,13 +453,8 @@ public function createTask($userDao)
453453
{
454454
$modelLoad = new MIDAS_ModelLoader();
455455
$batchmakeTaskModel = $modelLoad->loadModel('Task', 'batchmake');
456-
$taskDao = $batchmakeTaskModel->createTask($userDao);
457-
$userId = $taskDao->getUserId();
458-
$taskId = $taskDao->getKey();
459-
$subdirs = array(MIDAS_BATCHMAKE_SSP_DIR, $userId, $taskId);
460-
// create a workDir based on the task and user
461-
$workDir = KWUtils::createSubDirectories($this->configTmpDir . "/", $subdirs);
462-
return $workDir;
456+
$taskDao = $batchmakeTaskModel->createTask($userDao, $this->configTmpDir);
457+
return $taskDao;
463458
}
464459

465460
/**
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
CREATE TABLE batchmake_task (
1+
CREATE TABLE IF NOT EXISTS batchmake_task (
22
batchmake_task_id bigint(20) NOT NULL AUTO_INCREMENT,
33
user_id bigint(20) NOT NULL,
4+
work_dir text,
45
PRIMARY KEY (batchmake_task_id)
5-
);
6+
) DEFAULT CHARSET=utf8;
67

7-
8-
CREATE TABLE batchmake_itemmetric (
8+
CREATE TABLE IF NOT EXISTS batchmake_itemmetric (
99
itemmetric_id bigint(20) NOT NULL AUTO_INCREMENT,
1010
metric_name character varying(64) NOT NULL,
1111
bms_name character varying(256) NOT NULL,
1212
PRIMARY KEY (itemmetric_id)
13-
);
13+
) DEFAULT CHARSET=utf8;

modules/batchmake/database/pgsql/0.1.0.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
CREATE TABLE batchmake_task (
22
batchmake_task_id serial PRIMARY KEY,
3-
user_id bigint NOT NULL
3+
user_id bigint NOT NULL,
4+
work_dir text
45
);
56

67

modules/batchmake/models/base/TaskModelBase.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
1010
PURPOSE. See the above copyright notices for more information.
1111
=========================================================================*/
12+
include_once BASE_PATH . '/modules/batchmake/constant/module.php';
1213
/** TaskModel Base class */
1314
class Batchmake_TaskModelBase extends Batchmake_AppModel {
1415

@@ -23,15 +24,15 @@ public function __construct()
2324

2425
$this->_mainData = array(
2526
'batchmake_task_id' => array('type' => MIDAS_DATA),
26-
'user_id' => array('type' => MIDAS_DATA, )
27-
);
27+
'user_id' => array('type' => MIDAS_MANY_TO_ONE, 'model' => 'User', 'parent_column' => 'user_id', 'child_column' => 'user_id'),
28+
'work_dir' => array('type' => MIDAS_DATA));
2829
$this->initialize(); // required
2930
}
3031

3132

3233
/** Create a task
3334
* @return TaskDao */
34-
function createTask($userDao)
35+
function createTask($userDao, $tmpWorkDirRoot)
3536
{
3637
if(!$userDao instanceof UserDao)
3738
{
@@ -41,7 +42,13 @@ function createTask($userDao)
4142
$task = new Batchmake_TaskDao();
4243
$task->setUserId($userDao->getKey());
4344
$this->save($task);
44-
45+
$userId = $task->getUserId();
46+
$taskId = $task->getKey();
47+
$subdirs = array(MIDAS_BATCHMAKE_SSP_DIR, $userId, $taskId);
48+
// create a workDir based on the task and user
49+
$workDir = KWUtils::createSubDirectories($tmpWorkDirRoot . "/", $subdirs);
50+
$task->setWorkDir($workDir);
51+
$this->save($task);
4552
return $task;
4653
} // end createTask()
4754

modules/batchmake/tests/controllers/components/KWBatchmakeComponentTest.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ public function testPreparePipelineScripts()
152152
{
153153
$usersFile = $this->loadData('User', 'default');
154154
$userDao = $this->User->load($usersFile[0]->getKey());
155-
$workDir = $this->kwBatchmakeComponent->createTask($userDao);
155+
$taskDao = $this->kwBatchmakeComponent->createTask($userDao);
156+
$workDir = $taskDao->getWorkDir();
156157

157158
$scriptName = 'anotherscript.bms';
158159
$expectedSet = array("myscript.bms", "Myscript2.bms",
@@ -192,7 +193,8 @@ public function testPreparePipelineBmms()
192193
{
193194
$usersFile = $this->loadData('User', 'default');
194195
$userDao = $this->User->load($usersFile[0]->getKey());
195-
$workDir = $this->kwBatchmakeComponent->createTask($userDao);
196+
$taskDao = $this->kwBatchmakeComponent->createTask($userDao);
197+
$workDir = $taskDao->getWorkDir();
196198

197199
// try a script that refers to a non-existant bmm
198200
$scriptName = 'bmmswitherrors.bms';
@@ -247,7 +249,8 @@ public function testCompileBatchMakeScript()
247249
{
248250
$usersFile = $this->loadData('User', 'default');
249251
$userDao = $this->User->load($usersFile[0]->getKey());
250-
$workDir = $this->kwBatchmakeComponent->createTask($userDao);
252+
$taskDao = $this->kwBatchmakeComponent->createTask($userDao);
253+
$workDir = $taskDao->getWorkDir();
251254

252255
// a script that compiles
253256
$scriptName = 'Compiles.bms';
@@ -313,7 +316,8 @@ public function testGenerateCondorDag()
313316
{
314317
$usersFile = $this->loadData('User', 'default');
315318
$userDao = $this->User->load($usersFile[0]->getKey());
316-
$workDir = $this->kwBatchmakeComponent->createTask($userDao);
319+
$taskDao = $this->kwBatchmakeComponent->createTask($userDao);
320+
$workDir = $taskDao->getWorkDir();
317321

318322
// try a script that returns a non-zero value
319323
$scriptName = 'CompileReturnNonzero.bms';
@@ -353,7 +357,8 @@ public function testCondorSubmitDag()
353357
{
354358
$usersFile = $this->loadData('User', 'default');
355359
$userDao = $this->User->load($usersFile[0]->getKey());
356-
$workDir = $this->kwBatchmakeComponent->createTask($userDao);
360+
$taskDao = $this->kwBatchmakeComponent->createTask($userDao);
361+
$workDir = $taskDao->getWorkDir();
357362

358363
// try a script that returns a non-zero value
359364
$scriptName = 'CompileReturnNonzero.dagjob';

modules/batchmake/tests/models/base/TaskModelTest.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ public function testCreateTask()
3232

3333
$user1Dao = $usersFile[0];
3434

35-
$task1Dao = $taskModel->createTask($user1Dao);
35+
$tmpWorkDirRoot = KWUtils::getTempDirectory() . '/' . 'test';
36+
KWUtils::mkDir($tmpWorkDirRoot);
37+
38+
$task1Dao = $taskModel->createTask($user1Dao, $tmpWorkDirRoot);
3639

3740
$this->assertNotEmpty($task1Dao);
3841
$this->assertTrue($task1Dao instanceof Batchmake_TaskDao);
@@ -47,7 +50,7 @@ public function testCreateTask()
4750
// now try a different user
4851
$user2Dao = $usersFile[1];
4952

50-
$task2Dao = $taskModel->createTask($user2Dao);
53+
$task2Dao = $taskModel->createTask($user2Dao, $tmpWorkDirRoot);
5154
$this->assertNotEmpty($task2Dao);
5255
$this->assertTrue($task2Dao instanceof Batchmake_TaskDao);
5356
$userId2 = $task2Dao->getUserId();
@@ -68,6 +71,9 @@ public function testCreateTask()
6871

6972
$task4Dao = $taskModel->load($taskId2);
7073
$this->assertTrue($taskModel->compareDao($task2Dao, $task4Dao));
74+
75+
// now clean up
76+
KWUtils::recursiveRemoveDirectory($tmpWorkDirRoot);
7177
}
7278

7379

0 commit comments

Comments
 (0)