# Open the archive
return p.open(path)
- def delete_file(self, path, not_before=None):
- self.db.execute("INSERT INTO queue_delete(path, not_before) \
- VALUES(%s, %s)", path, not_before)
-
- def cleanup_files(self):
- query = self.db.query("SELECT * FROM queue_delete \
- WHERE (not_before IS NULL OR not_before <= NOW())")
-
- for row in query:
- if not row.path:
- continue
-
- path = row.path
-
- if not path or not path.startswith("%s/" % PAKFIRE_DIR):
- log.warning("Cannot delete file outside of the tree")
- continue
-
- try:
- logging.debug("Removing %s..." % path)
- os.unlink(path)
- except OSError as e:
- logging.error("Could not remove %s: %s" % (path, e))
-
- while True:
- path = os.path.dirname(path)
-
- # Stop if we are running outside of the tree.
- if not path.startswith(PAKFIRE_DIR):
- break
-
- # If the directory is not empty, we cannot remove it.
- if os.path.exists(path) and os.listdir(path):
- break
-
- try:
- logging.debug("Removing %s..." % path)
- os.rmdir(path)
- except OSError as e:
- logging.error("Could not remove %s: %s" % (path, e))
- break
+ async def cleanup(self):
+ """
+ Called regularly to cleanup any left-over resources
+ """
+ # Sessions
+ await self.sessions.cleanup()
- self.db.execute("DELETE FROM queue_delete WHERE id = %s", row.id)
+ # Uploads
+ await self.uploads.cleanup()
# Alias function
get = get_by_session_id
- def cleanup(self):
- # Delete all sessions that are not valid any more.
- self.db.execute("DELETE FROM sessions WHERE valid_until < NOW()")
+ async def cleanup(self):
+ """
+ Deletes all sessions that are not valid any more
+ """
+ with self.db.transaction():
+ self.db.execute("DELETE FROM sessions WHERE valid_until < CURRENT_TIMESTAMP")
class Session(base.DataObject):
# Synchronize repositories once every five minutes
*/5 * * * * pakfire pakfire-build-service repo:sync
+# Cleanup
+*/5 * * * * pakfire pakfire-build-service cleanup
+
# Check build dependencies
#* * * * * root pakfire-build-service check-build-dependencies &>/dev/null
# Send updates to Bugzilla
#*/5 * * * * pakfire pakfire-build-service send-bug-updates &>/dev/null
-# Cleanup files
-#*/5 * * * * pakfire pakfire-build-service cleanup-files &>/dev/null
-
-# Cleanup uploads once an hour
-#0 * * * * pakfire pakfire-build-service uploads:cleanup
-
-# Cleanup expired sessions
-#0 0 * * * pakfire pakfire-build-service cleanup-sessions &>/dev/null
-
# Run mirror check
#*/30 * * * * pakfire pakfire-build-service check-mirrors &>/dev/null
ALTER SEQUENCE public.packages_properties_id_seq OWNED BY public.packages_properties.id;
---
--- Name: queue_delete; Type: TABLE; Schema: public; Owner: pakfire
---
-
-CREATE TABLE public.queue_delete (
- id integer NOT NULL,
- path text NOT NULL,
- not_before timestamp without time zone
-);
-
-
-ALTER TABLE public.queue_delete OWNER TO pakfire;
-
---
--- Name: queue_delete_id_seq; Type: SEQUENCE; Schema: public; Owner: pakfire
---
-
-CREATE SEQUENCE public.queue_delete_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1;
-
-
-ALTER TABLE public.queue_delete_id_seq OWNER TO pakfire;
-
---
--- Name: queue_delete_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: pakfire
---
-
-ALTER SEQUENCE public.queue_delete_id_seq OWNED BY public.queue_delete.id;
-
-
--
-- Name: relation_sizes; Type: VIEW; Schema: public; Owner: pakfire
--
ALTER TABLE ONLY public.packages_properties ALTER COLUMN id SET DEFAULT nextval('public.packages_properties_id_seq'::regclass);
---
--- Name: queue_delete id; Type: DEFAULT; Schema: public; Owner: pakfire
---
-
-ALTER TABLE ONLY public.queue_delete ALTER COLUMN id SET DEFAULT nextval('public.queue_delete_id_seq'::regclass);
-
-
--
-- Name: repositories id; Type: DEFAULT; Schema: public; Owner: pakfire
--
ADD CONSTRAINT idx_2198147_primary PRIMARY KEY (id);
---
--- Name: queue_delete idx_2198155_primary; Type: CONSTRAINT; Schema: public; Owner: pakfire
---
-
-ALTER TABLE ONLY public.queue_delete
- ADD CONSTRAINT idx_2198155_primary PRIMARY KEY (id);
-
-
--
-- Name: repositories_builds idx_2198189_primary; Type: CONSTRAINT; Schema: public; Owner: pakfire
--
# Bugzilla
"bugzilla:version" : self.backend.bugzilla.version,
+ # Cleanup
+ "cleanup" : self.backend.cleanup,
+
# Repositories
"repos:sync" : self.backend.repos.sync,
"repos:write" : self.backend.repos.write,
# Run mirror check
#"check-mirrors" : self.backend.mirrors.check,
- # Cleanup files
- #"cleanup-files" : self.backend.cleanup_files,
-
- # Cleanup sessions
- #"cleanup-sessions" : self.backend.sessions.cleanup,
-
# Dist
#"dist" : self.backend.sources.dist,
# Send bug updates to Bugzilla
#"send-bug-updates" : self.backend.bugzilla.send_all,
-
- # Cleanup uploads
- #"uploads:cleanup" : self.backend.uploads.cleanup,
}
async def __call__(self, *args):