mirror of
				https://github.com/ohwgiles/laminar.git
				synced 2025-06-13 12:54:29 +00:00 
			
		
		
		
	resolves #22: allow keeping N rundirs
This replaces LAMINAR_KEEP_RUNDIR (bool) with LAMINAR_KEEP_RUNDIRS (int)
This commit is contained in:
		
							parent
							
								
									74443c292a
								
							
						
					
					
						commit
						76e0e9e62a
					
				@ -490,7 +490,7 @@ make
 | 
			
		||||
- `LAMINAR_BIND_HTTP`: The interface/port or unix socket on which `laminard` should listen for incoming connections to the web frontend. Default `*:8080`
 | 
			
		||||
- `LAMINAR_BIND_RPC`: The interface/port or unix socket on which `laminard` should listen for incoming commands such as build triggers. Default `unix-abstract:laminar`
 | 
			
		||||
- `LAMINAR_TITLE`: The page title to show in the web frontend.
 | 
			
		||||
- `LAMINAR_KEEP_RUNDIR`: If set, do not delete run directories after completion
 | 
			
		||||
- `LAMINAR_KEEP_RUNDIRS`: Set to an integer defining how many rundirs to keep per job. The lowest-numbered ones will be deleted. The default is 0, meaning all run dirs will be immediately deleted.
 | 
			
		||||
- `LAMINAR_ARCHIVE_URL`: If set, the web frontend served by `laminard` will use this URL to form links to artefacts archived jobs. Must be synchronized with web server configuration.
 | 
			
		||||
 | 
			
		||||
### Script execution order
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										11
									
								
								laminar.conf
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								laminar.conf
									
									
									
									
									
								
							@ -33,12 +33,15 @@
 | 
			
		||||
#LAMINAR_TITLE=
 | 
			
		||||
 | 
			
		||||
###
 | 
			
		||||
### LAMINAR_KEEP_RUNDIR
 | 
			
		||||
### LAMINAR_KEEP_RUNDIRS
 | 
			
		||||
###
 | 
			
		||||
### If set (to anything), the job rundir $LAMINAR_HOME/run/$JOB/$RUN
 | 
			
		||||
### will not be deleted after the run has completed
 | 
			
		||||
### Setting this prevents the immediate deletion of job rundirs
 | 
			
		||||
### $LAMINAR_HOME/run/$JOB/$RUN. Value should be an integer represeting
 | 
			
		||||
### the number of rundirs to keep.
 | 
			
		||||
###
 | 
			
		||||
#LAMINAR_KEEP_RUNDIR=1
 | 
			
		||||
### Default: 0
 | 
			
		||||
###
 | 
			
		||||
#LAMINAR_KEEP_RUNDIRS=0
 | 
			
		||||
 | 
			
		||||
###
 | 
			
		||||
### LAMINAR_ARCHIVE_URL
 | 
			
		||||
 | 
			
		||||
@ -73,7 +73,7 @@ Laminar::Laminar() {
 | 
			
		||||
    archiveUrl = ARCHIVE_URL_DEFAULT;
 | 
			
		||||
    if(char* envArchive = getenv("LAMINAR_ARCHIVE_URL"))
 | 
			
		||||
        archiveUrl = envArchive;
 | 
			
		||||
    eraseRunDir = true;
 | 
			
		||||
    numKeepRunDirs = 0;
 | 
			
		||||
    homeDir = getenv("LAMINAR_HOME") ?: "/var/lib/laminar";
 | 
			
		||||
 | 
			
		||||
    db = new Database((fs::path(homeDir)/"laminar.sqlite").string().c_str());
 | 
			
		||||
@ -393,8 +393,8 @@ void Laminar::stop() {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool Laminar::loadConfiguration() {
 | 
			
		||||
    if(getenv("LAMINAR_KEEP_RUNDIR"))
 | 
			
		||||
        eraseRunDir = false;
 | 
			
		||||
    if(const char* ndirs = getenv("LAMINAR_KEEP_RUNDIRS"))
 | 
			
		||||
        numKeepRunDirs = atoi(ndirs);
 | 
			
		||||
 | 
			
		||||
    NodeMap nm;
 | 
			
		||||
 | 
			
		||||
@ -757,12 +757,28 @@ void Laminar::runFinished(Run * r) {
 | 
			
		||||
        w->complete(r);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // remove the rundir
 | 
			
		||||
    if(eraseRunDir)
 | 
			
		||||
        fs::remove_all(r->runDir);
 | 
			
		||||
 | 
			
		||||
    // will delete the job
 | 
			
		||||
    // erase reference to run from activeJobs
 | 
			
		||||
    activeJobs.get<2>().erase(r);
 | 
			
		||||
 | 
			
		||||
    // remove old run directories
 | 
			
		||||
    // We cannot count back the number of directories to keep from the currently
 | 
			
		||||
    // finishing job because there may well be older, still-running instances of
 | 
			
		||||
    // this job and we don't want to delete their rundirs. So instead, check
 | 
			
		||||
    // whether there are any more active runs of this job, and if so, count back
 | 
			
		||||
    // from the oldest among them. If there are none, count back from the latest
 | 
			
		||||
    // known build number of this job, which may not be that of the run that
 | 
			
		||||
    // finished here.
 | 
			
		||||
    auto it = activeJobs.get<4>().equal_range(r->name);
 | 
			
		||||
    uint oldestActive = (it.first == it.second)? buildNums[r->name] : (*it.first)->build - 1;
 | 
			
		||||
    for(int i = oldestActive - numKeepRunDirs; i > 0; i--) {
 | 
			
		||||
        fs::path d = fs::path(homeDir)/"run"/r->name/std::to_string(i);
 | 
			
		||||
        // Once the directory does not exist, it's probably not worth checking
 | 
			
		||||
        // any further. 99% of the time this loop should only ever have 1 iteration
 | 
			
		||||
        // anyway so hence this (admittedly debatable) optimization.
 | 
			
		||||
        if(!fs::exists(d))
 | 
			
		||||
            break;
 | 
			
		||||
        fs::remove_all(d);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool Laminar::getArtefact(std::string path, std::string& result) {
 | 
			
		||||
 | 
			
		||||
@ -85,7 +85,7 @@ private:
 | 
			
		||||
    std::string homeDir;
 | 
			
		||||
    std::set<LaminarClient*> clients;
 | 
			
		||||
    std::set<LaminarWaiter*> waiters;
 | 
			
		||||
    bool eraseRunDir;
 | 
			
		||||
    uint numKeepRunDirs;
 | 
			
		||||
    std::string archiveUrl;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user