Hi,
I'm looking for a way to do some long jobs in the background like (Custom mail sending, SMS calls, Push Notifications, Reports generation and any Remote Service Calls). It there a way to make this and I'm not aware of?
Thanks
Is there any reason you cannot use cron for those tasks?
@vzool I'm not sure if it will fit your use case exactly, but have you taken a look at Hooks? Hooks let you perform tasks on certain events in the API. You can use these to send texts when an item is updated, or send a push notification when a certain user logs in.
As @dekyfin mentioned, creating reports every week would be a cron task π
This sounds like something you would create specifically for your application, as mentioned above, CRON could be used for scheduled reporting tasks and Hooks could be used for notifications.
However, on the other hand, this does sound like a great idea for a "Task Scheduler Extension". The extension could provide an interface to build a "task" and schedule that to run, which I can see being useful for some situations where you rely on the data.
π€
We had a PR for a "Cron Job Manager" before, but I got so busy with other stuff didn't have time to review and then we release version 7.
As @shealavington said this can be done with cron job.
This is a nice feature to have. but as right now it can be done by using cron job to run an specific script, or instantiate a worker queue service in hooks to execute your custom hook.
Yes, I think I can do that @dekyfin. Using cron, which is simple and very effective.
But, I don't know what is the entry point for this. π€
@rijkvanzanten The use of Hooks is easy but expensive for a long run. I really do prefer to make API calls simple and fast as much as I can. So I consider to dedicate API endpoints to handle data only while any time consuming/dependable operations left for the "Background Tasks". π
@shealavington Yes, I need "Task Scheduler". This is what I'm looking for. π
The scheduler always waiting and looking for any scheduled/new task to run, this will help many many other to gain advantages of "Parallelism-Like" on directus. π€
We had a PR for a "Cron Job Manager" before, but I got so busy with other stuff didn't have time to review and then we release version 7.
As @shealavington said this can be done with cron job.
This is a nice feature to have. but as right now it can be done by using cron job to run an specific script, or instantiate a worker queue service in hooks to execute your custom hook.
Which one? π
@WellingGuzman I found it #2088 finally :laughing:
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Ideally, we'd have a system where you can have custom snippets of PHP (similar to hooks) that can be run at an interval. If these snippets have access to the Directus internal api's (like hooks), you should be able to do virtually whatever you want.
I think we should / could have a directus_tasks collection that keeps track of at what interval to run what function? And maybe use directus_activity for logs of said task?
I like that. Would the code to be executed be saved in the database (eg directus_tasks.code)? Would it be a reference to a file (maybe uploaded in Directus Files) so that it is language agnostic?
If the tasks define when it runs (start, frequency, end/iterations), and we have a simple CRON that fires every minute, then we can just check the tasks and run them as needed. Seems pretty straightforward.
That could be even easier @benhaynes.
If the file itself starts with something to tell the API how often to run, we don't need to the database in between. We could have an extensions/tasks folder with .php files that get fired
Interesting. So naming could use cron schedule expressions:
/extensions/tasks/[5_4_*_*_sun]task-name.php
We could also "disable" tasks just like other extensions, by pre-pending _ to the file-name.
Now this is starting to look like a nice clean solution that just needs a CRON parser to run/check every minute!
To achieve better clarity/visibility, we are now tracking feature requests within the Feature Request project board.
This issue being closed does not mean it's not being considered.
Most helpful comment
This sounds like something you would create specifically for your application, as mentioned above, CRON could be used for scheduled reporting tasks and Hooks could be used for notifications.
However, on the other hand, this does sound like a great idea for a "Task Scheduler Extension". The extension could provide an interface to build a "task" and schedule that to run, which I can see being useful for some situations where you rely on the data.
Examples:
π€