Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WatchDirectory Activity not working #1654

Closed
noxe opened this issue Oct 19, 2021 · 16 comments
Closed

WatchDirectory Activity not working #1654

noxe opened this issue Oct 19, 2021 · 16 comments
Labels
bug Something isn't working
Milestone

Comments

@noxe
Copy link
Contributor

noxe commented Oct 19, 2021

Hi,

as discussed on Discord - it seems that the WatchDirectory Activity only works when defining an workflow in code.

But i cannot get it working for an workflow designed at runtime via Designer - the workflow is never executed / started?

@sfmskywalker sfmskywalker added the bug Something isn't working label Nov 1, 2021
@sfmskywalker sfmskywalker added this to the Elsa 2.4 milestone Nov 1, 2021
@noxe
Copy link
Contributor Author

noxe commented Nov 25, 2021

cool thanks - seems like the builds are failing currently https://ci.appveyor.com/project/sfmskywalker/elsa/history

@noxe
Copy link
Contributor Author

noxe commented Nov 25, 2021

@sfmskywalker - thanks for the fix - i see it fires now after i create and publish an workflow at runtime in the designer.

but it does not start a new worfkow instance - should it? or i am missing something? Watch Directory is my start activity?

image

@sfmskywalker
Copy link
Member

It should be able to create new workflow instances when used as a starting activity. I will check to see why that's not happening.

@noxe
Copy link
Contributor Author

noxe commented Nov 25, 2021

thx - i only see that it does query the database on the Bookmark table - where activitytype is WatchDirectory - but i dont see any bookmark record in the database

@sfmskywalker
Copy link
Member

Right, that makes sense. For starting activities, they are stored as triggers in memory, not in the database. Only for suspended workflows will these be stored as bookmarks in the database.

@noxe
Copy link
Contributor Author

noxe commented Nov 25, 2021

ok - so is this an bug currently?

@sfmskywalker
Copy link
Member

Well, if it doesn't start new workflow instances when used as a starting activity, then that would be a bug.

However, I just tried but it works fine for me:
directory-watcher

@noxe
Copy link
Contributor Author

noxe commented Nov 25, 2021

hmm interessting - i am on latest preview from today :( will try once again after launch

@noxe
Copy link
Contributor Author

noxe commented Nov 25, 2021

i ust debugged the TriggerFinder - i see that the "WatchDirectory" is in the trigger stores - but it seems that the store has another Hash then the scoped hash - dont know what is going on here?

@noxe
Copy link
Contributor Author

noxe commented Nov 25, 2021

damn - just found the bug @sfmskywalker - i used "." as pattern - which does not work then - because the FileSystemWatcher does change this to "" - and so the bookmark is not found - because bookmark is stored as ".*" - while the pattern * is used query the store:

    private void StartWorkflow(FileSystemWatcher watcher, FileSystemEventArgs e)
    {
        var changeTypes = e.ChangeType;
        var notifyFilter = watcher.NotifyFilter;
        var path = watcher.Path;
        var pattern = watcher.Filter;

        var model = _mapper.Map<FileSystemEvent>(e);
        var bookmark = new FileSystemEventBookmark(path, pattern, changeTypes, notifyFilter);

@noxe
Copy link
Contributor Author

noxe commented Nov 25, 2021

github seems to have problems with the patter - i used * . * in the workflow - but filewatcher does an *

@noxe
Copy link
Contributor Author

noxe commented Nov 25, 2021

maybe as workaround - add an if (pattern == "* . *") patter = *; in the StartWorkflow method?

@noxe
Copy link
Contributor Author

noxe commented Nov 25, 2021

i still hava a problem with this - when i change the pattern to * - i see the workflow instance is created - but the workflow is never executed - until i restart the server. the workflow instance is in Idle state - i use hangfire dispatcher - maybe related to this?

@noxe
Copy link
Contributor Author

noxe commented Nov 25, 2021

ok - seems like some kind of race condition - i see ObjectDisposedExceptrions happening - and so further processing stops - in the StartWorkflow method - there is an async method - shoudnt there be an await?

 _workflowLaunchpad.UseService(s => s.CollectAndDispatchWorkflowsAsync(launchContext, new WorkflowInput(model)));

from what i see code runs across this and disposes the current scope ? @sfmskywalker

@noxe
Copy link
Contributor Author

noxe commented Nov 25, 2021

This need to be changed to

_workflowLaunchpad.UseServiceAsync(async s => await s.CollectAndDispatchWorkflowsAsync(launchContext, new WorkflowInput(model)));

then everything works fine :)

@noxe
Copy link
Contributor Author

noxe commented Nov 25, 2021

created an PR for this - please take a look if this is the correct approach

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants