-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
the thread sleep time
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,8 @@ | |
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.bladerunnerjs.api.App; | ||
import org.bladerunnerjs.api.BRJS; | ||
import org.bladerunnerjs.api.logging.Logger; | ||
import org.bladerunnerjs.api.model.exception.ModelOperationException; | ||
import org.bladerunnerjs.api.model.exception.request.ContentProcessingException; | ||
import org.bladerunnerjs.api.model.exception.request.MalformedRequestException; | ||
|
@@ -47,7 +49,7 @@ public BundlerHandler(BundlableNode bundlableNode) | |
} | ||
|
||
|
||
public void createBundleFile(File bundleFile, String bundlePath, String version) throws IOException, MalformedRequestException, ResourceNotFoundException, ContentProcessingException, ModelOperationException | ||
public void createBundleFile(BRJS brjs, File bundleFile, String bundlePath, String version) throws IOException, MalformedRequestException, ResourceNotFoundException, ContentProcessingException, ModelOperationException | ||
{ | ||
if (bundlePath.contains("\\")) | ||
{ | ||
|
@@ -56,7 +58,7 @@ public void createBundleFile(File bundleFile, String bundlePath, String version) | |
|
||
String modelRequestPath = getModelRequestPath(bundlePath); | ||
|
||
repeatedlyAttemptToCreateBundleFile(bundleFile); | ||
repeatedlyAttemptToCreateBundleFile(brjs, bundleFile); | ||
|
||
try (OutputStream bundleFileOutputStream = new FileOutputStream(bundleFile, false); | ||
ResponseContent content = BundleSetRequestHandler.handle(new JsTestDriverBundleSet(bundlableNode.getBundleSet()), modelRequestPath, new StaticContentAccessor(app), version); ) | ||
|
@@ -69,19 +71,24 @@ public void createBundleFile(File bundleFile, String bundlePath, String version) | |
|
||
// this is a workaround for the scenario where Windows indexing service or virus scanners etc can lock the file when we try to create it | ||
// see http://stackoverflow.com/a/10516563/2634854 for more info | ||
private void repeatedlyAttemptToCreateBundleFile(File bundleFile) throws IOException | ||
private void repeatedlyAttemptToCreateBundleFile(BRJS brjs, File bundleFile) throws IOException | ||
{ | ||
if (bundleFile.exists()) { | ||
throw new IOException( String.format("The bundle file '%s' already exists and should not. It should have previously been deleted so new content can be written to it", bundleFile.getAbsolutePath()) ); | ||
} | ||
bundleFile.getParentFile().mkdirs(); | ||
|
||
Logger logger = brjs.logger(this.getClass()); | ||
for (int i = 0; i < 100; i++) { | ||
try { | ||
if (i % 10 == 0) { // print log line every 10 iterations | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
andy-berry-dev
Member
|
||
logger.debug("Attempting to create an empty bundle file at '%s'.", bundleFile.getAbsolutePath()); | ||
} | ||
bundleFile.createNewFile(); | ||
if (bundleFile.isFile()) { | ||
return; | ||
} | ||
Thread.sleep(10); | ||
Thread.sleep(100); | ||
} catch (IOException | InterruptedException ex) { | ||
// ignore the exception from creating the file or thread interupted | ||
} | ||
|
@andyberry88, would it be better to just log to the user that it took N ms before we were able to write the file?