Giter Site home page Giter Site logo

Comments (6)

kkdlau avatar kkdlau commented on June 10, 2024 1

Hi @Frooodle, i think this is a good issue that can assign someone like me who wish to contribute to open source 😃

My initial idea of solving this issue is to update collectFilesForProcessing to ensure we only collects files that are fully copied, either by checking if the size is growing, or using some os level features (e.g. lsof)

let me if there is comment for the solution 😆

from stirling-pdf.

Frooodle avatar Frooodle commented on June 10, 2024

A good callout and bug
I will work on this over weekend

from stirling-pdf.

Frooodle avatar Frooodle commented on June 10, 2024

@kkdlau hows this going?

from stirling-pdf.

seakrebel avatar seakrebel commented on June 10, 2024

Here is an example. Haven't tested it. Also not an java expert. But could be leading into right direction.

PipelineDirectoryProcessor.java

// [...]
import java.util.concurrent.TimeUnit;
// [...]
public class PipelineDirectoryProcessor {
    // [...]

    private static final long STABILITY_CHECK_DELAY = 1000; // 1 second
    private static final long STABILITY_CHECK_COUNT = 5; // Check 5 times

    private File[] collectFilesForProcessing(Path dir, Path jsonFile, PipelineOperation operation) throws IOException {
        try (Stream<Path> paths = Files.list(dir)) {
            if ("automated".equals(operation.getParameters().get("fileInput"))) {
                return paths.filter(path -> !Files.isDirectory(path) && !path.equals(jsonFile) && isFileStable(path))
                            .map(Path::toFile)
                            .toArray(File[]::new);
            } else {
                String fileInput = (String) operation.getParameters().get("fileInput");
                return new File[] { new File(fileInput) };
            }
        }
    }

    private boolean isFileStable(Path path) throws IOException {
        long initialSize = Files.size(path);
        for (int i = 0; i < STABILITY_CHECK_COUNT; i++) {
            try {
                TimeUnit.MILLISECONDS.sleep(STABILITY_CHECK_DELAY);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
                throw new IOException("Thread interrupted during stability check", e);
            }
            long newSize = Files.size(path);
            if (initialSize != newSize) {
                return false;
            }
        }
        return initialSize > 0; // Also ensuring the file is not zero bytes
    }
    // [...]
}
// [...]

from stirling-pdf.

kkdlau avatar kkdlau commented on June 10, 2024

@kkdlau hows this going?

Hi, was busy with my full-time work 😞
But I already have the draft of the PR
Just need to go through couple of regression testing to ensure it doesn't break the existing features

Will create a PR tnt (APAC time)👍🏻

from stirling-pdf.

kkdlau avatar kkdlau commented on June 10, 2024

Here is an example. Haven't tested it. Also not an java expert. But could be leading into right direction.

PipelineDirectoryProcessor.java

// [...]

import java.util.concurrent.TimeUnit;

// [...]

public class PipelineDirectoryProcessor {

    // [...]



    private static final long STABILITY_CHECK_DELAY = 1000; // 1 second

    private static final long STABILITY_CHECK_COUNT = 5; // Check 5 times



    private File[] collectFilesForProcessing(Path dir, Path jsonFile, PipelineOperation operation) throws IOException {

        try (Stream<Path> paths = Files.list(dir)) {

            if ("automated".equals(operation.getParameters().get("fileInput"))) {

                return paths.filter(path -> !Files.isDirectory(path) && !path.equals(jsonFile) && isFileStable(path))

                            .map(Path::toFile)

                            .toArray(File[]::new);

            } else {

                String fileInput = (String) operation.getParameters().get("fileInput");

                return new File[] { new File(fileInput) };

            }

        }

    }



    private boolean isFileStable(Path path) throws IOException {

        long initialSize = Files.size(path);

        for (int i = 0; i < STABILITY_CHECK_COUNT; i++) {

            try {

                TimeUnit.MILLISECONDS.sleep(STABILITY_CHECK_DELAY);

            } catch (InterruptedException e) {

                Thread.currentThread().interrupt();

                throw new IOException("Thread interrupted during stability check", e);

            }

            long newSize = Files.size(path);

            if (initialSize != newSize) {

                return false;

            }

        }

        return initialSize > 0; // Also ensuring the file is not zero bytes

    }

    // [...]

}

// [...]

Thanks for the idea 👍🏻
My draft is quite similar except for isFileStable implementation
will share more details when I open the PR

from stirling-pdf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.