-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#38 Testing Framework - background execution of approve and import jobs
- Loading branch information
1 parent
82ecee9
commit 1a62a55
Showing
3 changed files
with
112 additions
and
18 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
core/libs/image-importer/src/main/java/gallerymine/backend/pool/BackgroundJobRunner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package gallerymine.backend.pool; | ||
|
||
public abstract class BackgroundJobRunner implements Runnable { | ||
|
||
private String name = null; | ||
|
||
public String getName() { | ||
return this.name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
} |
61 changes: 61 additions & 0 deletions
61
core/libs/image-importer/src/main/java/gallerymine/backend/pool/MiscBackgroundJobsPool.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package gallerymine.backend.pool; | ||
|
||
import gallerymine.backend.beans.AppConfig; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | ||
import org.springframework.stereotype.Component; | ||
|
||
/** | ||
* Manages Pool of BackgroundJobs | ||
* Created by sergii_puliaiev on 8/03/18. | ||
*/ | ||
@Component | ||
public class MiscBackgroundJobsPool { | ||
|
||
private static Logger log = LoggerFactory.getLogger(MiscBackgroundJobsPool.class); | ||
|
||
@Autowired | ||
private ApplicationContext context; | ||
|
||
@Autowired | ||
private AppConfig appConfig; | ||
|
||
private ThreadPoolTaskExecutor pool; | ||
|
||
public MiscBackgroundJobsPool() { | ||
pool = new ThreadPoolTaskExecutor(); | ||
pool.setCorePoolSize(10); | ||
pool.setMaxPoolSize(10); | ||
pool.setWaitForTasksToCompleteOnShutdown(true); | ||
|
||
pool.setThreadGroupName("MiscBackJobPool"); | ||
pool.setThreadNamePrefix("MiscBackJobPool_"); | ||
|
||
pool.initialize(); | ||
} | ||
|
||
public void executeRequest(String name, Runnable runnerJob) { | ||
if (runnerJob == null) { | ||
return; | ||
} | ||
BackgroundJobRunner runner = new BackgroundJobRunner() { | ||
@Override | ||
public void run() { | ||
Thread.currentThread().setName(Thread.currentThread().getName()+"-"+getName()); | ||
try { | ||
runnerJob.run(); | ||
} catch (Exception e){ | ||
log.error("Failed back job with name {}. Reason: {}", getName(), e.getMessage(), e); | ||
} | ||
} | ||
}; | ||
runner.setName(name); | ||
log.info(" Misc Background Job request execution id={} and path={}", name); | ||
pool.execute(runner); | ||
log.info(" Misc Background Job scheduled id={} and path={}", name); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters