php-resque icon indicating copy to clipboard operation
php-resque copied to clipboard

Delete job functionality

Open francislavoie opened this issue 7 years ago • 4 comments

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 to Job.php which would have the job delete itself from redis, something like $this->redis->del(self::redisKey($this));
  • add a setExpiry(int seconds) function to Job.php which can manually set the expiry time. This could indirectly be used to delete things by setting the seconds to 0 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 in Job.php

I think both are good options, we could implement them both. They cover different use-cases.

Thoughts?

francislavoie avatar Mar 15 '17 03:03 francislavoie

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.

xelan avatar Mar 16 '17 13:03 xelan

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]

mplx avatar Mar 17 '17 15:03 mplx

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.

francislavoie avatar Mar 17 '17 15:03 francislavoie

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

PAXANDDOS avatar Feb 20 '23 15:02 PAXANDDOS