1717use OCP \App \IAppManager ;
1818use OCP \AppFramework \Utility \ITimeFactory ;
1919use OCP \BackgroundJob \IJobList ;
20- use OCP \BackgroundJob \QueuedJob ;
20+ use OCP \BackgroundJob \TimedJob ;
2121use OCP \Files \IRootFolder ;
2222
23- class FileSystemListenerJob extends QueuedJob {
23+ class FileSystemListenerJob extends TimedJob {
2424 private const BATCH_SIZE = 500 ;
2525
2626 public function __construct (
@@ -34,6 +34,8 @@ public function __construct(
3434 private IRootFolder $ rootFolder ,
3535 ) {
3636 parent ::__construct ($ timeFactory );
37+ $ this ->allowParallelRuns = false ;
38+ $ this ->setInterval (5 * 60 ); // 5 minutes
3739 }
3840
3941 protected function run ($ argument ): void {
@@ -50,40 +52,37 @@ protected function run($argument): void {
5052 return ;
5153 }
5254
53- try {
54- foreach ($ fsEvents as $ fsEvent ) {
55- $ this ->diagnosticService ->sendHeartbeat (static ::class, $ this ->getId ());
55+ foreach ($ fsEvents as $ fsEvent ) {
56+ $ this ->diagnosticService ->sendHeartbeat (static ::class, $ this ->getId ());
5657
57- try {
58- $ node = current ($ this ->rootFolder ->getUserFolder ($ fsEvent ->getUserId ())->getById ($ fsEvent ->getNodeId ()));
59- if ($ node === false ) {
60- $ this ->logger ->warning ('Node with ID ' . $ fsEvent ->getNodeId () . ' not found for fs event " ' . $ fsEvent ->getType () . '" ' );
61- $ this ->fsEventMapper ->delete ($ fsEvent );
62- continue ;
63- }
58+ try {
59+ $ node = current ($ this ->rootFolder ->getUserFolder ($ fsEvent ->getUserId ())->getById ($ fsEvent ->getNodeId ()));
60+ } catch (\Exception $ e ) {
61+ $ this ->logger ->warning ('Error retrieving node for fs event " ' . $ fsEvent ->getType () . '": ' . $ e ->getMessage (), ['exception ' => $ e ]);
62+ $ node = false ;
63+ }
64+ if ($ node === false ) {
65+ $ this ->logger ->warning ('Node with ID ' . $ fsEvent ->getNodeId () . ' not found for fs event " ' . $ fsEvent ->getType () . '" ' );
66+ $ this ->fsEventMapper ->delete ($ fsEvent );
67+ continue ;
68+ }
6469
65- switch ($ fsEvent ->getTypeObject ()) {
66- case FsEventType::CREATE :
67- $ this ->fsEventService ->onInsert ($ node );
68- break ;
69- case FsEventType::ACCESS_UPDATE_DECL :
70- $ this ->fsEventService ->onAccessUpdateDecl ($ node );
71- break ;
72- }
73- $ this ->diagnosticService ->sendHeartbeat (static ::class, $ this ->getId ());
74- $ this ->fsEventMapper ->delete ($ fsEvent );
75- } catch (\RuntimeException $ e ) {
76- $ this ->logger ->warning ('Error handling fs event " ' . $ fsEvent ->getType () . '": ' . $ e ->getMessage (), ['exception ' => $ e ]);
70+ try {
71+ switch ($ fsEvent ->getTypeObject ()) {
72+ case FsEventType::CREATE :
73+ $ this ->fsEventService ->onInsert ($ node );
74+ break ;
75+ case FsEventType::ACCESS_UPDATE_DECL :
76+ $ this ->fsEventService ->onAccessUpdateDecl ($ node );
77+ break ;
7778 }
79+ $ this ->diagnosticService ->sendHeartbeat (static ::class, $ this ->getId ());
80+ $ this ->fsEventMapper ->delete ($ fsEvent );
81+ } catch (\RuntimeException $ e ) {
82+ $ this ->logger ->warning ('Error handling fs event " ' . $ fsEvent ->getType () . '": ' . $ e ->getMessage (), ['exception ' => $ e ]);
7883 }
79- } catch (\Throwable $ e ) {
80- // schedule in 5mins
81- $ this ->jobList ->scheduleAfter (static ::class, $ this ->time ->getTime () + 5 * 60 );
82- throw $ e ;
8384 }
8485
85- // schedule in 5mins
86- $ this ->jobList ->scheduleAfter (static ::class, $ this ->time ->getTime () + 5 * 60 );
8786 $ this ->diagnosticService ->sendJobEnd (static ::class, $ this ->getId ());
8887 }
8988}
0 commit comments