php-resque
php-resque copied to clipboard
Delete job functionality
So, we have a default expiry for jobs, but I have a use-case where I want to get rid of data as quick as possible for security reasons. I want to handle sensitive data with jobs but once it's processed I want to get rid of the payload as quickly as possible.
We have this issue https://github.com/mjphaynes/php-resque/issues/34 which kinda ties into this a bit.
I propose two options:
- add a
delete()
function toJob.php
which would have the job delete itself from redis, something like$this->redis->del(self::redisKey($this));
- add a
setExpiry(int seconds)
function toJob.php
which can manually set the expiry time. This could indirectly be used to delete things by setting the seconds to0
I think. e.g.$this->redis->expire(self::redisKey($this), seconds);
(we'd need to validate the inputs here), in addition this function could replace this usage of$this->redis->expire
inJob.php
I think both are good options, we could implement them both. They cover different use-cases.
Thoughts?
Great suggestions, thank you! You're right, probably both would be useful in different contexts/use cases. I agree that proper input validation and error handling are very important when implementing this feature.
Thinking of use-cases maybe the expiry time could be split into several scenarios?
- expiry time for succeeded jobs [if a jobs succeeds it will be removed from redis within a individual timeframe; currently 1w?]
- expiry time for failed jobs [if a jobs fails it will be removed from redis within a individual timeframe; currently: never?]
- expiry time until execution [if a job is not performed (started) by a worker within an individual timeframe its removed from the queue; currently not implemented]
Yeah, that makes sense. Good ideas :+1:
I might want to only expire a certain class of jobs though, so manual control as I suggested would still be very good.
Wait... was this implemented? Kinda looking for such a function but it appears I'll have to delete the job somehow else
Seems the only way to delete the job is by creating Predis\Client
instance and using del()
:
(\Resque\Redis::instance())->del("resque:job:jobId")
but job still somehow "remains in memory" after scanning for them with lrange()
or zrevrangebyscore()
or within the stats. Have to load this job using Job::load()
which will return null
for such deleted jobs