Comments (13)
One problem i do see with multiple job methods per class is that extending Minion::Job
would become rather tricky. So the feature will probably not be in the first proposal.
from minion.
I've been thinking about doing something like this many times. But not sure yet what the best way to implement it would be.
from minion.
Whatever we end up with, i do want using job classes to be as easy as $minion->add_task(foo => 'Some::FooJobClass')
.
from minion.
I imagine a simple job class would look like this (translated from our basic example):
package MyApp::Task::PokeMojo;
use Mojo::Base 'Minion::Job', -signatures;
sub run ($self, @args) {
$self->app->ua->get('mojolicious.org');
$self->app->log->debug('We have poked mojolicious.org for a visitor');
});
1;
And then you'd register it in your app with:
$minion->add_task(poke_mojo => 'MyApp::Task::PokeMojo');
And enqueue it like any other job:
$minion->enqueue('poke_mojo');
Keeping the task a Minion::Job
subclass will ensure that event based extensions (using the dequeue
event from Minion::Worker
) keep working. And give us access to all the lower level APIs in Minion::Job
for new extensions on the task level.
from minion.
from minion.
@rabbiveesh There will definitely not be any routing shenanigans with name translation. Multiple methods are worth considering though.
$minion->add_task(poke_mojo => 'MyApp::Task::RandomStuff#poke_mojo');
from minion.
from minion.
If you want to factor out "base" code just stick your own base class between Minion::Job and PokeMojo
from minion.
We'll start experimenting with the feature in the next Minion release. 3fd1014...8ac422a
from minion.
Also, Role::Tiny exists
from minion.
Minion::Job determines that "Run" is the run method. Fiddle with that if you want in your sub class. So I do not see that as any problem
from minion.
I've tried using the subclass feature, and found it too rigid - one subclass per task doesn't seem to offer (to me at least) great advantages compared to registering tasks in a module.
I was looking for a way to add behaviours to tasks as in a question I'd asked on stackoverflow (https://stackoverflow.com/questions/65626783/setting-the-finish-event-on-a-mojolicious-minionjob).
It turned out that adding roles to tasks looks IMHO more fluent.
The way I did it was
- a task builder function that takes a subref as argument, plus options
- the task builder function wraps the subref in a job, adds roles to it
- and returns another subref that runs the job
It works ok with two roles I built - a timeout that kills the job if it runs longer than a given time, and one that posts to a URL when the job is finished or failed
app->minion->add_task(some_task => task(sub { my $job = shift; sleep 5; $job->app->log->info('I am a task'); return 'Done!'; }, { roles => { '+Alerter' => { 'alert_on' => [qw/finished failed/ ] } } }));
I am an amateur - not a pro - and new to this so bear with me pls. My code kind of sucks right now, but I could share after a little cleanup it if it helps. I found this approach more inline with the general Mojolicious/MInion way of doing things, so I thought I'd share it, I hope it's ok.
from minion.
The feature is done. More additions can be discussed in new issues.
from minion.
Related Issues (20)
- Add a Minion guide HOT 2
- [Feature Request] Add search bar to Minion Admin site HOT 7
- fix typo at Minion::Guide HOT 1
- [Feature Request] ability to filter delayed jobs HOT 1
- Incorrect count for attempts upon ultimate failure? HOT 3
- popper.js not found HOT 2
- [Feature request] allow signals to be sent to workers as well HOT 5
- A Mojolicious app w/ Minion::Backend::Pg always connects to PostgreSQL db on startup HOT 2
- Repair may stuck when many failed jobs HOT 6
- Batch enqueue HOT 2
- Support Content Security Policies HOT 5
- Minion.unlock() concurrency HOT 4
- [Feature Request] Minion Backend list_jobs: using args as search filter HOT 5
- Minion::Admin can not remove retry inactive task HOT 6
- [Feature Request] Include Test::Minion subclass/role of Test::Mojo HOT 10
- action buttons don't perform their actions, only redirect HOT 2
- Calling `finish`, `note` etc in task code fails on macOS while communicating over TCP HOT 6
- [Feature Request] Finalizier task for locks
- [ Feature request ] An event for progress? HOT 19
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from minion.