Comments (4)
It does, but yes, it should be made clearer that if you do want to use constructor arguments,
a) they must have default parameters, as the JobService will re-create the job class passing through no constructor params
b) you must have logic in your constructor that can determine if it's been constructed by the job service, or by user-land code, and whether the constructor params are to be used.
The kind of logic to use in your constructor could be something like
public function __construct($to = null) {
if ($to) {
// we know that we've been called by user code, so
// do the real initialisation work
}
}
Of course, the other alternative is to set properties on the job directly after constructing it from your own code.
from silverstripe-queuedjobs.
Actually, this was mentioned in the wiki, but I've made it a bit clearer, and referenced it from the README file
from silverstripe-queuedjobs.
@nyeholt thanks for somewhat clarifying this, but where exactly can I put the parameters passed in to the constructor of the job in order to persist / make this information available to the running of it across multiple steps?
For example public function __construct($startDate = null, $endDate = null). I want the start and end dates available in the process() function.
Is there something built in to the queued jobs to do this, or will I have to think up my own way of storing the parameters (in DB or file) and then loading them back in the setup() function?
Any guidance you can give on this would be greatly appreciated.
Thanks.
from silverstripe-queuedjobs.
I've made it a little clearer in the wiki page, and copy / pasted below
Job Properties QueuedJobs inherited from the AbstractQueuedJob have a default mechanism for persisting values via the __set and __get mechanism that stores items in the jobData map, which is serialize()d between executions of the job processing. All you need to do from within your job is call $this->myProperty = 'somevalue';
, and it will be automatically persisted for you; HOWEVER, on subsequent creation of the job object (ie, in the __constructor()
) these properties have not been loaded, so you cannot rely on them at that point.
from silverstripe-queuedjobs.
Related Issues (20)
- Immediate Jobs are never detected as stalled or broken HOT 2
- Queue keeps adding duplicate jobs and long-running php processes HOT 3
- Empty INFO messages each time process() is called HOT 1
- Minimum PHP Version HOT 4
- PHP version constraint HOT 1
- Run withouth user from CMS not working correctly
- CleanupJobs dont always get `reenqueue()`'d HOT 1
- Array to String conversion in checkJobHealth() HOT 1
- afterComplete sometimes doesn't run HOT 1
- Only administrators can view queued jobs HOT 1
- File locking should be configurable HOT 4
- Default jobs recreated multiple times HOT 1
- PHP 8.2: Dynamic properties deprecated, but are currently required for JobData? HOT 8
- Fresh install SilverStripe 4.11 + StaticPublisher HOT 8
- Errors during job initialisation aren't logged as messages against the job
- UI doesn't provide usefull search fields HOT 1
- Configuration option to disable Missing Default Job email HOT 1
- SS5 Queued Jobs 5.0.0: Gridfiled Admin pagination missing after search HOT 1
- onBefore/After actions HOT 2
- Silverstripe dataObject not found inside AbstractQueuedJob extending class HOT 3
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 silverstripe-queuedjobs.